sure would be nice to be able to create objects in the editor, huh?

This commit is contained in:
Laura Klünder 2024-12-05 13:13:35 +01:00
parent 15f2eab217
commit f2e92c1958
2 changed files with 10 additions and 4 deletions

View file

@ -227,8 +227,13 @@ class ChangedObjectCollection(BaseSchema):
for operation in operations: for operation in operations:
changed_object = self.objects.setdefault(operation.obj.model, {}).get(operation.obj.id, None) changed_object = self.objects.setdefault(operation.obj.model, {}).get(operation.obj.id, None)
if changed_object is None: if changed_object is None:
changed_object = ChangedObject(obj=operation.obj, # todo: titles should be better, probably
titles=self.prev.get(operation.obj).titles) titles = (
operation.fields.get("titles", {})
if isinstance(operation, CreateObjectOperation)
else self.prev.get(operation.obj).titles
)
changed_object = ChangedObject(obj=operation.obj, titles=titles)
self.objects[operation.obj.model][operation.obj.id] = changed_object self.objects[operation.obj.model][operation.obj.id] = changed_object
if isinstance(operation, CreateObjectOperation): if isinstance(operation, CreateObjectOperation):
changed_object.created = True changed_object.created = True

View file

@ -88,12 +88,13 @@ class DatabaseOverlayManager:
def handle_post_save(self, instance: Model, created: bool, update_fields: set | None, **kwargs): def handle_post_save(self, instance: Model, created: bool, update_fields: set | None, **kwargs):
field_values = self.get_model_field_values(instance) field_values = self.get_model_field_values(instance)
ref, pre_change_values = self.get_ref_and_pre_change_values(instance)
if created: if created:
ref = ObjectReference.from_instance(instance)
self.operations.append(CreateObjectOperation(obj=ref, fields=field_values)) self.operations.append(CreateObjectOperation(obj=ref, fields=field_values))
return return
ref, pre_change_values = self.get_ref_and_pre_change_values(instance)
if update_fields: if update_fields:
field_values = {name: value for name, value in field_values.items() if name in update_fields} field_values = {name: value for name, value in field_values.items() if name in update_fields}