#6108: send all_objects_to_be_deleted in the pre_delete signal
----------------------------------------------------------+-----------------
          Reporter:  Gábor Farkas <[EMAIL PROTECTED]>  |         Owner:  nobody
            Status:  new                                  |     Milestone:      
  
         Component:  Core framework                       |       Version:  SVN 
  
        Resolution:                                       |      Keywords:      
  
             Stage:  Design decision needed               |     Has_patch:  1   
  
        Needs_docs:  0                                    |   Needs_tests:  0   
  
Needs_better_patch:  1                                    |  
----------------------------------------------------------+-----------------
Comment (by gabor):

 the following (ugly) code should work:

 overload the delete() method of the object like this:

 {{{
     def delete(self):
         from django.utils.datastructures import SortedDict
         s = SortedDict()
         self._collect_sub_objects(s)
         #here s will contain all the objects that are planned to be
 deleted
         if s.items() == [(type(u), { u.pk : u })]:
             super(YourModel, self).delete()
         else:
             raise Exception("related objects found")
 }}}

 the code is untested, but i'm doing something very similar and it works.
 if you want to make it 100% safe, you have to run it in a serializable-
 transaction unfortunately :(
 otherwise it could happen, that the call to _collect_sub_objects returns
 that all is fine, but while the code proceeds to delete-the-object,
 some other process already inserted new "dependent" objects,
 and those will get deleted.

 yes, it contains a call to a '''private''' '''undocumented''' method.
 no, afaik no other way exists.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/6108#comment:5>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to