switch to decorator used to register property_fields and save it on Meta inner class to expose to cloned fastapi models
This commit is contained in:
5
ormar/decorators/__init__.py
Normal file
5
ormar/decorators/__init__.py
Normal file
@ -0,0 +1,5 @@
|
||||
from ormar.decorators.property_field import property_field
|
||||
|
||||
__all__ = [
|
||||
"property_field",
|
||||
]
|
||||
19
ormar/decorators/property_field.py
Normal file
19
ormar/decorators/property_field.py
Normal file
@ -0,0 +1,19 @@
|
||||
import inspect
|
||||
from collections.abc import Callable
|
||||
from typing import Union
|
||||
|
||||
from ormar.exceptions import ModelDefinitionError
|
||||
|
||||
|
||||
def property_field(func: Callable) -> Union[property, Callable]:
|
||||
if isinstance(func, property): # pragma: no cover
|
||||
func.fget.__property_field__ = True
|
||||
else:
|
||||
arguments = list(inspect.signature(func).parameters.keys())
|
||||
if len(arguments) > 1 or arguments[0] != "self":
|
||||
raise ModelDefinitionError(
|
||||
"property_field decorator can be used "
|
||||
"only on class methods with no arguments"
|
||||
)
|
||||
func.__dict__["__property_field__"] = True
|
||||
return func
|
||||
Reference in New Issue
Block a user