#18889: Provide a simple way to retain parent instances after children are 
deleted
----------------------------------------------+--------------------
     Reporter:  anonymous                     |      Owner:  nobody
         Type:  New feature                   |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.4
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 I have a Location table with two children (using table-inheritance):
 Restaurant and ChipShop. There should be a simple way to convert a
 ChipShop to a Restaurant without deleting/recreating the Location which
 may be referenced by lots of foreign keys, e.g:

 {{{
 location = Location.objects.get(1) # Currently a ChipShop
 restaurant = Restaurant(location_ptr=location)
 restaurant.save()
 location.chipshop.delete() # Deletes the ChipShop row but not the Location
 }}}


 Currently this can be achieved by using raw sql to bypass django's code
 that deletes the parent when a child is deleted. Doing the following does
 not work as the parent is still deleted, perhaps this is a bug?

 {{{
 class ChipShop(Location);
    location_ptr = models.OneToOneField(Location, on_delete=DO_NOTHING,
 parent_link=True)
 }}}

 Modifying the on_delete of the created location_ptr does nothing as well.
 Perhaps a setting in the parents Meta that could be used to specify that
 the parent should not be deleted when the child is?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18889>
Django <https://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 https://groups.google.com/groups/opt_out.


Reply via email to