def test_related_model_edits(self): with revision: queen = Artist(name='Queen') queen.save() a_kind_of_magic = Album(artist=queen, title='A Kind of Magic') a_kind_of_magic.save() dont_lose_your_head = Song(album=a_kind_of_magic, title="Don't Lose Your Head") dont_lose_your_head.save() first_revision = revision.latest_transactions['default'] with revision: princes_of_the_universe = Song(album=a_kind_of_magic, title='Princes of the Universe') princes_of_the_universe.save() dont_lose_your_head.seconds = 278 dont_lose_your_head.save() second_revision = revision.latest_transactions['default'] with revision: princes_of_the_universe.seconds = 212 princes_of_the_universe.save() friends_will_be_friends = Song(album=a_kind_of_magic, title='Friends Will Be Friends') friends_will_be_friends.save() third_revision = revision.latest_transactions['default'] with revision: # the a_kind_of_magic album was not modified after the initial commit. Verify that we can retrieve the a_kind_of_magic model from the various versions first_a_kind_of_magic = Album.objects.version(first_revision).get(pk=a_kind_of_magic.pk) second_a_kind_of_magic = Album.objects.version(second_revision).get(pk=a_kind_of_magic.pk) third_a_kind_of_magic = Album.objects.version(third_revision).get(pk=a_kind_of_magic.pk) # Verify that the data is the same. self.assertEqual(revision.data(first_a_kind_of_magic)['field'], revision.data(second_a_kind_of_magic)['field']) self.assertEqual(revision.data(second_a_kind_of_magic)['field'], revision.data(third_a_kind_of_magic)['field']) # Verify that princes_of_the_universe does not exist at the first_revision (it was created on the second revision) self.assertRaises(ObjectDoesNotExist, first_a_kind_of_magic.songs.get, pk=princes_of_the_universe.pk) # Verify that retrieving the object from the reverse relationship and directly from the Song objects yield the same result. self.assertEqual(second_a_kind_of_magic.songs.get(pk=princes_of_the_universe.pk).__dict__, Song.objects.version(second_revision).get(pk=princes_of_the_universe.pk).__dict__) # Verify that retrieval of the object from the reverse relationship return the correct versions of the objects. second_princes_of_the_universe = second_a_kind_of_magic.songs.get(pk=princes_of_the_universe.pk) self.assertEqual(second_princes_of_the_universe.seconds, None) third_princes_of_the_universe = third_a_kind_of_magic.songs.get(pk=princes_of_the_universe.pk) self.assertEqual(third_princes_of_the_universe.seconds, 212) # Verify that the first revision of a_kind_of_magic has one song self.assertEquals(len(first_a_kind_of_magic.songs.all()), 1) # Verify that the second revision of a_kind_of_magic has two songs self.assertEquals(len(second_a_kind_of_magic.songs.all()), 2) # Verify that the third revision of a_kind_of_magic has three songs self.assertEquals(len(third_a_kind_of_magic.songs.all()), 3)