Custom properties¶
AMSDAL allows you to define custom properties or methods for your models.
For example, with the following model schema:
{
"title": "Person",
"type": "object",
"properties": {
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
}
},
"required": [
"first_name",
"last_name"
]
}
You can add easily the custom property full_name
that will combine values of the first_name
and
last_name
properties by creating the file full_name.py
inside the properties
folder next to your model.json
schema file.
@property
def full_name(self):
return f'{self.first_name} {self.last_name}'
This method will be automatically added to your model class during model generation, so you will be able to use it as a common python property:
from models.user.person import Person
person = Person(first_name='John', last_name='Doe')
print(person.full_name) # John Doe
In the same way, you can add custom methods to your model classes to extend functionality and avoid code duplication.
Info
You can read more about custom properties in the AMSDAL CLI documentation.