django-reversion で関連オブジェクトを復元するにはどうすればよいですか。
私は動作しない次のことを試しました...
models.py:
@reversion.register(follow=['bar_set',])
class Foo(models.Model):
def save(self, *args, **kwargs):
with transaction.atomic(), reversion.create_revision():
return super(Foo, self).save(*args, **kwargs)
@reversion.register
class Bar(models.Model):
foo = models.ForeignKey(Foo)
def save(self, *args, **kwargs):
with transaction.atomic(), reversion.create_revision():
return super(Bar, self).save(*args, **kwargs)
そして次のテスト
test.py:
class TestModels(TestCase):
def test_soft_delete(self):
from myapp.models import Foo, Bar
a = Foo()
a.save()
b1 = Bar(foo=a)
b1.save()
b2 = Bar(foo=a)
b2.save()
a.delete()
self.assertEqual(0, Foo.objects.count())
self.assertEqual(0, Bar.objects.count())
version = reversion.get_deleted(Foo)[0] # There is only one.
version.revert()
self.assertEqual(1, Foo.objects.count())
self.assertEqual(2, Bar.objects.count()) # HERE IT FAILS: 2 != 0