🎨 Add Schema.get method
This commit is contained in:
parent
ed55c3708f
commit
a3d9862c4e
1 changed files with 6 additions and 3 deletions
|
|
@ -39,9 +39,7 @@ class ModelMeta(type(TortoiseModel)):
|
||||||
|
|
||||||
class BoundSchema:
|
class BoundSchema:
|
||||||
def __call__(self, readonly: bool = False):
|
def __call__(self, readonly: bool = False):
|
||||||
if readonly:
|
return self.get(readonly)
|
||||||
return self.readonly
|
|
||||||
return self.model
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def model(self):
|
def model(self):
|
||||||
|
|
@ -68,6 +66,11 @@ class ModelMeta(type(TortoiseModel)):
|
||||||
exclude_readonly=True,
|
exclude_readonly=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get(self, readonly: bool = False):
|
||||||
|
if readonly:
|
||||||
|
return self.readonly
|
||||||
|
return self.model
|
||||||
|
|
||||||
new_cls.Schema = BoundSchema()
|
new_cls.Schema = BoundSchema()
|
||||||
return new_cls
|
return new_cls
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue