Skip to content

Instantly share code, notes, and snippets.

@i
Created July 19, 2018 18:29
Show Gist options
  • Save i/20b5fb2594fe43d96d08152a847cd0c0 to your computer and use it in GitHub Desktop.
Save i/20b5fb2594fe43d96d08152a847cd0c0 to your computer and use it in GitHub Desktop.
class User(SoftDeleteModel):
name = models.CharField(null=False, blank=False)
class Cat(SoftDeleteModel):
owner = models.ForeignKey(
User,
null=True,
blank=True,
on_delete=models.SET_NULL)
ian = User.new(name='Ian')
pichael = Cat.new(name='Pichael', owner=ian)
ian.delete()
print(pichael.owner) # should print None
# Now there should be a Snapshot that looks like this:
# {
# id: 1,
# root_id: ian.id,
# snapshot_records: [
# { record_id: ian.id, foreign_key: null },
# { record_id: pichael.id, foreign_key: "owner_id:{ian.id}" }
# ]
# }
ian.restore()
print(pichael.owner) # should be ian
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment