refactor: Sort fields alphabetically and prioritize fields with DIRECT_TYPES in Template class
Sort the fields alphabetically and prioritize fields with DIRECT_TYPES in the Template class. This improves the organization and readability of the code, ensuring that fields with specific types are listed first.
This commit is contained in:
parent
2b1786f791
commit
3862afc907
1 changed files with 3 additions and 1 deletions
|
|
@ -23,7 +23,9 @@ class Template(BaseModel):
|
|||
# first sort alphabetically
|
||||
# then sort fields so that fields that have .field_type in DIRECT_TYPES are first
|
||||
self.fields.sort(key=lambda x: x.name)
|
||||
self.fields.sort(key=lambda x: x.field_type in DIRECT_TYPES, reverse=False)
|
||||
self.fields.sort(
|
||||
key=lambda x: x.field_type in DIRECT_TYPES if hasattr(x, "field_type") else False, reverse=False
|
||||
)
|
||||
|
||||
@model_serializer(mode="wrap")
|
||||
def serialize_model(self, handler):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue