move include and exclude checks
This commit is contained in:
@ -178,13 +178,22 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
|
||||
self._orm.remove_parent(self, name)
|
||||
|
||||
@classmethod
|
||||
def get_properties(cls) -> List[str]:
|
||||
return [
|
||||
def get_properties(
|
||||
cls,
|
||||
include: Union["AbstractSetIntStr", "MappingIntStrAny"] = None,
|
||||
exclude: Union["AbstractSetIntStr", "MappingIntStrAny"] = None,
|
||||
) -> List[str]:
|
||||
props = [
|
||||
prop
|
||||
for prop in dir(cls)
|
||||
if isinstance(getattr(cls, prop), property)
|
||||
and prop not in ("__values__", "__fields__", "fields", "pk_column")
|
||||
]
|
||||
if include:
|
||||
props = [prop for prop in props if prop in include]
|
||||
if exclude:
|
||||
props = [prop for prop in props if prop not in exclude]
|
||||
return props
|
||||
|
||||
def dict( # noqa A003
|
||||
self,
|
||||
@ -226,11 +235,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
|
||||
dict_instance[field] = None
|
||||
|
||||
# include model properties as fields
|
||||
props = self.get_properties()
|
||||
if include:
|
||||
props = [prop for prop in props if prop in include]
|
||||
if exclude:
|
||||
props = [prop for prop in props if prop not in exclude]
|
||||
props = self.get_properties(include=include, exclude=exclude)
|
||||
if props:
|
||||
dict_instance.update({prop: getattr(self, prop) for prop in props})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user