Ticket #16781: t16781-tests-modeltest-reverse_lookup-multi_level_test.diff
File t16781-tests-modeltest-reverse_lookup-multi_level_test.diff, 3.2 KB (added by , 13 years ago) |
---|
-
tests/regressiontests/queries/models.py
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py index 3238f61..609d3c7 100644
a b class OneToOneCategory(models.Model): 343 343 def __unicode__(self): 344 344 return "one2one " + self.new_name 345 345 346 class User(models.Model): 347 name = models.CharField(max_length=50) 348 349 def __unicode__(self): 350 return self.name 351 352 class Address(models.Model): 353 user = models.ForeignKey(User) 354 address = models.CharField(max_length=100) 355 356 class Relationship(models.Model): 357 status = models.CharField(max_length=1) 358 from_user = models.ForeignKey(User, related_name='relationships_from') 359 to_user = models.ForeignKey(User, related_name='relationships_to') 360 -
tests/regressiontests/queries/tests.py
diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py index 708e60d..442ee26 100644
a b from models import (Annotation, Article, Author, Celebrity, Child, Cover, Detail 15 15 DumbCategory, ExtraInfo, Fan, Item, LeafA, LoopX, LoopZ, ManagedModel, 16 16 Member, NamedCategory, Note, Number, Plaything, PointerA, Ranking, Related, 17 17 Report, ReservedName, Tag, TvChef, Valid, X, Food, Eaten, Node, ObjectA, ObjectB, 18 ObjectC, CategoryItem, SimpleCategory, SpecialCategory, OneToOneCategory) 18 ObjectC, CategoryItem, SimpleCategory, SpecialCategory, OneToOneCategory, User, 19 Address, Relationship) 19 20 20 21 21 22 class BaseQuerysetTest(TestCase): … … class Queries5Tests(TestCase): 1276 1277 ) 1277 1278 1278 1279 1280 class Queries7Tests(TestCase): 1281 def setUp(self): 1282 john = User.objects.create(name="John Doe") 1283 jim = User.objects.create(name="Jim Bo") 1284 jerry = User.objects.create(name="Jerry Noh") 1285 first_address = Address.objects.create( 1286 address="First address", 1287 user=john 1288 ) 1289 second_address = Address.objects.create( 1290 address="Second address", 1291 user=jim 1292 ) 1293 jerry_is_johns_friend = Relationship.objects.create( 1294 status='f', 1295 from_user=john, 1296 to_user=jerry 1297 ) 1298 john_is_jerrys_enemy = Relationship.objects.create( 1299 status='e', 1300 from_user=jerry, 1301 to_user=john 1302 ) 1303 1304 def test_ticket16781_same_reverse_field(self): 1305 u1 = User.objects.get(name__exact="Jerry Noh") 1306 # Retrieve all polls for which the user is not the From User in a From-User relationship 1307 address1 = Address.objects.exclude(user__relationships_from__from_user__id=u1.id) 1308 self.assertEqual(address1.count(), 1) 1309 1310 def test_ticket16781_differing_reverse_field(self): 1311 u1 = User.objects.get(name__exact="Jerry Noh") 1312 # Retrieve all polls for which the user is not the From User in a To-User relationship 1313 address1 = Address.objects.exclude(user__relationships_to__from_user__id=u1.id) 1314 self.assertEqual(address1.count(), 1) 1315 1316 1279 1317 class SelectRelatedTests(TestCase): 1280 1318 def test_tickets_3045_3288(self): 1281 1319 # Once upon a time, select_related() with circular relations would loop