#12899: Explicitly allow to keep alive objects after deleting related ForeignKey
object instance
------------------------------------------+---------------------------------
 Reporter:  rudi                          |       Owner:  nobody    
   Status:  new                           |   Milestone:  1.2       
Component:  Database layer (models, ORM)  |     Version:  1.2-beta  
 Keywords:  foreignkey, relations         |       Stage:  Unreviewed
Has_patch:  0                             |  
------------------------------------------+---------------------------------
 Sometimes relation between objects needs to be 'weak': on deleting
 'parent' object we should define some 'fallback' keeping 'children'
 instanses alive.

 It would look like this:

 {{{
 #!python

 class MyModel(Model):
     user = ForeignKey(User, blank=True, null=True, weak=True)
 }}}

 or

 {{{
 #!python

 def get_or_create_default_user(instance):
     # some project specific logic here to define
     # default user for MyModel instace
     # ...
     return user

 class MyModel(Model):
     user = ForeignKey(User, default=get_or_create_default_user, weak=True)
 }}}

 This will help prevent tricks with signal 'pre_delete' #6870.

 Suggested processing of 'weak' relation: just before deleting 'parent' all
 related 'weak' relations must be set to default. If 'parent' is the same
 as default, then deleting of related objects will occur anyway. If not,
 related objects will survive :)

-- 
Ticket URL: <http://code.djangoproject.com/ticket/12899>
Django <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