tags:

views:

40

answers:

1

Hi , I am facing a problem in django development. Actually I am created a Model which include foreign keys of 4 other models . Now I user these all models at at admin site. Problem is that when I delete a record which is used a foriegn key in my main model then this deletion process also delete record from my main model . I required that if a model include a forign key of any other model then if I delete this foreign key model record from admin then no record must be deleted from the model which is using this model as foreign key .

Can any one have idea that how can I stop this 'ON DELETE CASCADE'

I shall be very thank full to you. Regards

+1  A: 

Override MyObj.delete() to iterate through all the keyed relations you want to keep, set their reference back to the object you are deleting to null. Then, once all the relations are unhooked, call super(MyObj, self).delete()

You may have to update your database (and model definitions) to allow null=True for those keys you are unhooking.

stevejalim