sure would be nice to be able to create objects in the editor, huh?
This commit is contained in:
parent
15f2eab217
commit
f2e92c1958
2 changed files with 10 additions and 4 deletions
|
@ -227,8 +227,13 @@ class ChangedObjectCollection(BaseSchema):
|
|||
for operation in operations:
|
||||
changed_object = self.objects.setdefault(operation.obj.model, {}).get(operation.obj.id, None)
|
||||
if changed_object is None:
|
||||
changed_object = ChangedObject(obj=operation.obj,
|
||||
titles=self.prev.get(operation.obj).titles)
|
||||
# todo: titles should be better, probably
|
||||
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
|
||||
if isinstance(operation, CreateObjectOperation):
|
||||
changed_object.created = True
|
||||
|
|
|
@ -88,12 +88,13 @@ class DatabaseOverlayManager:
|
|||
def handle_post_save(self, instance: Model, created: bool, update_fields: set | None, **kwargs):
|
||||
field_values = self.get_model_field_values(instance)
|
||||
|
||||
ref, pre_change_values = self.get_ref_and_pre_change_values(instance)
|
||||
|
||||
if created:
|
||||
ref = ObjectReference.from_instance(instance)
|
||||
self.operations.append(CreateObjectOperation(obj=ref, fields=field_values))
|
||||
return
|
||||
|
||||
ref, pre_change_values = self.get_ref_and_pre_change_values(instance)
|
||||
|
||||
if update_fields:
|
||||
field_values = {name: value for name, value in field_values.items() if name in update_fields}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue