PageRenderTime 61ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/m2m_regress/models.py

https://code.google.com/p/mango-py/
Python | 58 lines | 34 code | 13 blank | 11 comment | 0 complexity | 70725d7de962c1d7b02f7d2ec6dcaaf9 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. from django.db import models
  2. from django.contrib.auth import models as auth
  3. # No related name is needed here, since symmetrical relations are not
  4. # explicitly reversible.
  5. class SelfRefer(models.Model):
  6. name = models.CharField(max_length=10)
  7. references = models.ManyToManyField('self')
  8. related = models.ManyToManyField('self')
  9. def __unicode__(self):
  10. return self.name
  11. class Tag(models.Model):
  12. name = models.CharField(max_length=10)
  13. def __unicode__(self):
  14. return self.name
  15. # Regression for #11956 -- a many to many to the base class
  16. class TagCollection(Tag):
  17. tags = models.ManyToManyField(Tag, related_name='tag_collections')
  18. def __unicode__(self):
  19. return self.name
  20. # A related_name is required on one of the ManyToManyField entries here because
  21. # they are both addressable as reverse relations from Tag.
  22. class Entry(models.Model):
  23. name = models.CharField(max_length=10)
  24. topics = models.ManyToManyField(Tag)
  25. related = models.ManyToManyField(Tag, related_name="similar")
  26. def __unicode__(self):
  27. return self.name
  28. # Two models both inheriting from a base model with a self-referential m2m field
  29. class SelfReferChild(SelfRefer):
  30. pass
  31. class SelfReferChildSibling(SelfRefer):
  32. pass
  33. # Many-to-Many relation between models, where one of the PK's isn't an Autofield
  34. class Line(models.Model):
  35. name = models.CharField(max_length=100)
  36. class Worksheet(models.Model):
  37. id = models.CharField(primary_key=True, max_length=100)
  38. lines = models.ManyToManyField(Line, blank=True, null=True)
  39. # Regression for #11226 -- A model with the same name that another one to
  40. # which it has a m2m relation. This shouldn't cause a name clash between
  41. # the automatically created m2m intermediary table FK field names when
  42. # running syncdb
  43. class User(models.Model):
  44. name = models.CharField(max_length=30)
  45. friends = models.ManyToManyField(auth.User)