Ticket #8106: queries.models.patch

File queries.models.patch, 1.6 KB (added by Camron Flanders <camron.flanders@…>, 16 years ago)

regressiontest patch for this ticket.

  • regressiontests/queries/models.py

     
    217217    a = models.ForeignKey(LeafA)
    218218    b = models.ForeignKey(LeafB)
    219219
     220
     221# model hierarchy, for ticket #8106
     222class User(models.Model):
     223    name = models.CharField(max_length=200)
     224   
     225class Person(models.Model):
     226    user = models.ForeignKey("User", unique=True)
     227
     228class Organizer(models.Model):
     229    person = models.ForeignKey("Person")
     230
     231class Student(models.Model):
     232    person = models.ForeignKey("Person")
     233
     234class Class(models.Model):
     235    org = models.ForeignKey("Organizer")
     236
     237class Enrollment(models.Model):
     238    std = models.ForeignKey("Student")
     239    claz = models.ForeignKey("Class")
     240
     241
     242
    220243__test__ = {'API_TESTS':"""
    221244>>> t1 = Tag.objects.create(name='t1')
    222245>>> t2 = Tag.objects.create(name='t2', parent=t1)
     
    887910>>> Celebrity.objects.count() == num_celebs
    888911True
    889912
     913Bug #8106 --
     914>>> us = User(name="std")
     915>>> us.save()
     916>>> usp = Person(user=us)
     917>>> usp.save()
     918
     919>>> uo = User(name="org")
     920>>> uo.save()
     921>>> uop = Person(user=uo)
     922>>> uop.save()
     923
     924>>> s = Student(person = usp)
     925>>> s.save()
     926>>> o = Organizer(person = uop)
     927>>> o.save()
     928
     929>>> c = Class(org=o)
     930>>> c.save()
     931>>> e = Enrollment(std=s, claz=c)
     932>>> e.save()
     933
     934>>> e_related = Enrollment.objects.all().select_related()[0]
     935>>> print e_related.std.person.user.name
     936std
     937>>> print e_related.claz.org.person.user.name
     938org
     939
    890940"""}
    891941
    892942# In Python 2.3, exceptions raised in __len__ are swallowed (Python issue
Back to Top