mirror of
https://github.com/django/django.git
synced 2024-11-18 23:44:22 +00:00
c1584383fa
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12276 bcc190cf-cafb-0310-a4f2-bffc1f526a37
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
from django.test import TestCase
|
|
from django.contrib.contenttypes.models import ContentType
|
|
from models import Link, Place, Restaurant, Person, Address
|
|
|
|
class GenericRelationTests(TestCase):
|
|
|
|
def test_inherited_models_content_type(self):
|
|
"""
|
|
Test that GenericRelations on inherited classes use the correct content
|
|
type.
|
|
"""
|
|
|
|
p = Place.objects.create(name="South Park")
|
|
r = Restaurant.objects.create(name="Chubby's")
|
|
l1 = Link.objects.create(content_object=p)
|
|
l2 = Link.objects.create(content_object=r)
|
|
self.assertEqual(list(p.links.all()), [l1])
|
|
self.assertEqual(list(r.links.all()), [l2])
|
|
|
|
def test_reverse_relation_pk(self):
|
|
"""
|
|
Test that the correct column name is used for the primary key on the
|
|
originating model of a query. See #12664.
|
|
"""
|
|
p = Person.objects.create(account=23, name='Chef')
|
|
a = Address.objects.create(street='123 Anywhere Place',
|
|
city='Conifer', state='CO',
|
|
zipcode='80433', content_object=p)
|
|
|
|
qs = Person.objects.filter(addresses__zipcode='80433')
|
|
self.assertEqual(1, qs.count())
|
|
self.assertEqual('Chef', qs[0].name)
|