Skip to content

Commit

Permalink
Merge pull request #157 from ynput/155-allow-creating-project-level-e…
Browse files Browse the repository at this point in the history
…ntities-with-explicit-id

Optional explicit ID for project level entities post requests
  • Loading branch information
martastain authored Apr 29, 2024
2 parents fd0b7da + d8dabf0 commit c814502
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions ayon_server/entities/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,27 @@ def _generate_entity_model(self) -> Type[BaseModel]:
def _generate_post_model(self) -> Type[BaseModel]:
"""Generate the post model."""
model_name = f"{self.entity_name.capitalize()}PostModel"
fields = [
f
for f in (self.fields + self._project_level_fields + self._common_fields)
if not f.get("dynamic")
]
# Allow setting the ID explicitly
fields = (
[
{
"name": "id",
"type": "string",
"title": "Entity ID",
"factory": "uuid",
"description": "Explicitly set the ID of the entity",
"regex": ENTITY_ID_REGEX,
"example": ENTITY_ID_EXAMPLE,
}
]
if self.has_id
else []
)
for f in self.fields + self._project_level_fields + self._common_fields:
if f.get("dynamic"):
continue
fields.append(f)

return generate_model(model_name, fields, EntityModelConfig)

def _generate_patch_model(self) -> Type[BaseModel]:
Expand Down

0 comments on commit c814502

Please sign in to comment.