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:
ogabrielluiz 2024-06-13 16:29:00 -03:00
commit 3862afc907

View file

@ -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):