My fault, I must have skipped right over that part. It seems that it
*does* send pre_delete and post_delete signals, but does not call
custom delete methods

On Jun 17, 9:51 am, Daniel Hepper <[EMAIL PROTECTED]> wrote:
> > It isn't very clear from that sentence which of the two methods Django
> > uses to delete those child records, but looking at the code, it seems
> > to be method #2. Since it's using the more-efficient batch delete, no
> > custom delete methods are being called, no signals are being sent,
> > which is exactly the problem you're having.
>
> > The solution is to override the delete method (or respond to the
> > pre_delete signal), on your *parent* model, in this case
> > 'Participant'. That way, when you delete the Participant, you can
> > delete all related Data records by hand.
>
> I had a quick glance at the code and I came to the opposite conclusion.
>
> A comment [1] in the delete() method in the QuerySet class says:
>
> "# Collect all the objects to be deleted in this chunk, and all the
>  # objects that are related to the objects that are to be deleted."
>
> This collection is then passed to the delete_objects [2] function where
> the SQL magic happens and it definitely sends signals.
>
> Confused as I was, I just tried it. I have a Video model which haa a
> VideoHost model as foreign key. I defined a function that prints its
> parameter and attached it to the post_delete signal:
>
> >>> def print_sig(*args,**kwargs):
>
> ...     for x in args: print str(x)
> ...     for k,v in kwargs.items(): print k,v
>
> >>> dispatcher.connect(print_sig, signal=signals.post_delete)
>
> Then I deleted one VideoHost[3]:
>
> >>> VideoHost.objects.all()[0].delete()
>
> All related Videos got deleted as well, and signals got sent:
>
> instance Video 1 on YouTube
> signal <object object at 0xb7d8f4a8>
> sender <class 'videosite.videos.models.Video'>
> instance Video 2 on YouTube
> signal <object object at 0xb7d8f4a8>
> sender <class 'videosite.videos.models.Video'>
> instance Video 3 on YouTube
> signal <object object at 0xb7d8f4a8>
> sender <class 'videosite.videos.models.Video'>
> instance YouTube
> signal <object object at 0xb7d8f4a8>
> sender <class 'videosite.videos.models.VideoHost'>
>
> It seems signals are the way to go, or did I miss something?
>
> Regards,
> Daniel
>
> [1]http://code.djangoproject.com/browser/django/trunk/django/db/models/q...
> [2]http://code.djangoproject.com/browser/django/trunk/django/db/models/q...
> [3] OMG, I deleted YouTube! :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to