views:

15

answers:

2

hi,

in Django admin site when you decide to suppress an object, all the linked element (ie: elements pointed at by a foreign key) are also deleted.

How do you dodge this, except making raw queries in the shell? Is it possible to tune the admin to have the choice? Thanks

A: 

You just need to override the delete method of the models in question.

Generic example:

class Foo:

    def delete(self):
        """
        Override default model method so that all objects in the related
        objects set are not removed
        """
        self.my_related_stuff.clear()
        super(Foo, self).delete()

See this article for more examples:

http://fragmentsofcode.wordpress.com/2009/03/06/django-gotcha-related-objects-deleted-by-default/

André Laszlo
A: 

You can hack around it, but there is no proper way of doing it.

Take a look at these links for possible workarounds:

WoLpH