Tuesday, July 28, 2015

Re: post_delete and determining if a related object has been deleted

> This makes no sense to me. You want to delete an Item or Order but
> then immediately create a new one?

My actual goal is this: Whenever an Item object itself is deleted, I
want to create a LogEntry object attached to the item's order. If an
order is deleted however, I don't want to do anything.

In code, I expected it to look something like this:

@receiver(post_delete, sender=Item)
def on_item_post_delete(instance, **kwargs):
if instance.order is not None:
LogEntry(order=instance.order).save()

It's technically impossible (AFAIK) however to determine the case
between "Item alone is deleted" and "Item is cascaded by Order
deletion", at the moment.

This also has to do with deferred constraint checking with the
PostgreSQL backend. If contraints were checked immediately, then the
insert would probably fail instantly, instead of the failing
transaction, which I can't handle myself anymore.

I'm really out of ideas.

Stefan

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/55B77764.2000506%40boxbox.org.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment