Restoring deleted entries with db_constraint = False

12 views
Skip to first unread message

Olivier Dalang

unread,
Apr 7, 2016, 1:33:07 PM4/7/16
to django...@googlegroups.com
Hi,

I need to implement the ability to restore deleted entries in the admin. Django-reversion handles this, but it doesn't seem to work well with relations : they aren't restored (at least in my tests).

I thought of setting

class MainModel(models.Model):
    ...
class RelatedModel(models.Model):
    fk = models.ForeignKey( 'MainModel', db_constraint=False, on_delete=models.DO_NOTHING ) 

so that the related entries are kept when the main entries are deleted, and that whenever I restore the MainModel, the RelatedModel will still be there.

I'm not sure if this is a great idea or if this will cause trouble at some point. The doc says :
That said, here are some scenarios where you might want to do this:
- You have legacy data that is not valid.
- You’re sharding your database.
 and I'm in neither of these scenarios...
 
I'd love some advice to know whether I'm on the verge of doing something stupid ;)

Thanks !

Olivier Dalang
Reply all
Reply to author
Forward
0 new messages