Tuesday, July 28, 2015

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

> Den 28/07/2015 kl. 09.37 skrev Stefan Schindler <stsch@boxbox.org>:
>
> If the Order object itself is deleted, all post_delete handlers of all
> related objects are fired, including Item. Item however stores a new
> object with a relation to the *deleted Order* object, which will
> result in a constraint error (at least when using transactions in
> PostgreSQL, which I do).

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

If you want to delete an Order but make sure the Item stays, you should use the "on_delete=SET_NULL" argument of ForeignKey fields: https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.ForeignKey.on_delete

Erik

--
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/D25DE259-4267-4010-A683-1F3A745D6FD0%40cederstrand.dk.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment