Ticket #15146: tests.diff
File tests.diff, 1.6 KB (added by , 14 years ago) |
---|
-
tests/modeltests/reverse_lookup/tests.py
1 1 from django.test import TestCase 2 2 from django.core.exceptions import FieldError 3 3 4 from models import User, Poll, Choice 4 from models import User, Poll, Choice, Person 5 5 6 6 class ReverseLookupTests(TestCase): 7 7 … … 41 41 related_choice__name__exact="This is the answer.") 42 42 self.assertEqual(p2.question, "What's the second question?") 43 43 44 def test_reverse_by_related_name_without_saving(self): 45 p1 = Person() 46 p1.save() 47 p2 = Person() 48 self.assertEqual(p2.children.all(), "[]") 49 50 p2.save() 51 self.assertEqual(p2.children.all(), "[]") 52 44 53 def test_reverse_field_name_disallowed(self): 45 54 """ 46 55 If a related_name is given you can't use the field name instead 47 56 """ 48 57 self.assertRaises(FieldError, Poll.objects.get, 49 58 choice__name__exact="This is the answer") 59 -
tests/modeltests/reverse_lookup/models.py
26 26 27 27 def __unicode__(self): 28 28 return self.name 29 30 class Person(models.Model): 31 parent = models.ForeignKey('self', blank=True, null=True, related_name='children') 32