PageRenderTime 19ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/regressiontests/many_to_one_regress/models.py

https://code.google.com/p/mango-py/
Python | 46 lines | 25 code | 13 blank | 8 comment | 0 complexity | c4f0e25b523aa5fe3141b47c7d3196c6 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. """
  2. Regression tests for a few ForeignKey bugs.
  3. """
  4. from django.db import models
  5. # If ticket #1578 ever slips back in, these models will not be able to be
  6. # created (the field names being lower-cased versions of their opposite
  7. # classes is important here).
  8. class First(models.Model):
  9. second = models.IntegerField()
  10. class Second(models.Model):
  11. first = models.ForeignKey(First, related_name = 'the_first')
  12. # Protect against repetition of #1839, #2415 and #2536.
  13. class Third(models.Model):
  14. name = models.CharField(max_length=20)
  15. third = models.ForeignKey('self', null=True, related_name='child_set')
  16. class Parent(models.Model):
  17. name = models.CharField(max_length=20)
  18. bestchild = models.ForeignKey('Child', null=True, related_name='favored_by')
  19. class Child(models.Model):
  20. name = models.CharField(max_length=20)
  21. parent = models.ForeignKey(Parent)
  22. # Multiple paths to the same model (#7110, #7125)
  23. class Category(models.Model):
  24. name = models.CharField(max_length=20)
  25. def __unicode__(self):
  26. return self.name
  27. class Record(models.Model):
  28. category = models.ForeignKey(Category)
  29. class Relation(models.Model):
  30. left = models.ForeignKey(Record, related_name='left_set')
  31. right = models.ForeignKey(Record, related_name='right_set')
  32. def __unicode__(self):
  33. return u"%s - %s" % (self.left.category.name, self.right.category.name)