models.py 855 B

12345678910111213141516171819202122232425262728293031
  1. """
  2. Many-to-many and many-to-one relationships to the same table
  3. Make sure to set ``related_name`` if you use relationships to the same table.
  4. """
  5. from __future__ import unicode_literals
  6. from django.db import models
  7. from django.utils import six
  8. from django.utils.encoding import python_2_unicode_compatible
  9. class User(models.Model):
  10. username = models.CharField(max_length=20)
  11. @python_2_unicode_compatible
  12. class Issue(models.Model):
  13. num = models.IntegerField()
  14. cc = models.ManyToManyField(User, blank=True, related_name='test_issue_cc')
  15. client = models.ForeignKey(User, models.CASCADE, related_name='test_issue_client')
  16. def __str__(self):
  17. return six.text_type(self.num)
  18. class Meta:
  19. ordering = ('num',)
  20. class UnicodeReferenceModel(models.Model):
  21. others = models.ManyToManyField("UnicodeReferenceModel")