2006-05-02 09:31:56 +08:00
|
|
|
"""
|
2007-03-24 04:17:04 +08:00
|
|
|
29. Many-to-many and many-to-one relationships to the same table
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2006-06-01 03:23:07 +08:00
|
|
|
Make sure to set ``related_name`` if you use relationships to the same table.
|
2006-05-02 09:31:56 +08:00
|
|
|
"""
|
2012-06-08 00:08:47 +08:00
|
|
|
from __future__ import unicode_literals
|
2006-05-02 09:31:56 +08:00
|
|
|
|
|
|
|
from django.db import models
|
2012-07-20 20:48:51 +08:00
|
|
|
from django.utils import six
|
2012-08-12 18:32:08 +08:00
|
|
|
from django.utils.encoding import python_2_unicode_compatible
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2011-10-14 02:04:12 +08:00
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
class User(models.Model):
|
2007-08-05 13:14:46 +08:00
|
|
|
username = models.CharField(max_length=20)
|
2006-05-02 09:31:56 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
@python_2_unicode_compatible
|
2006-05-02 09:31:56 +08:00
|
|
|
class Issue(models.Model):
|
|
|
|
num = models.IntegerField()
|
|
|
|
cc = models.ManyToManyField(User, blank=True, related_name='test_issue_cc')
|
|
|
|
client = models.ForeignKey(User, related_name='test_issue_client')
|
2006-06-01 03:23:07 +08:00
|
|
|
|
2012-08-12 18:32:08 +08:00
|
|
|
def __str__(self):
|
2012-07-20 20:48:51 +08:00
|
|
|
return six.text_type(self.num)
|
2006-06-01 03:10:43 +08:00
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
class Meta:
|
|
|
|
ordering = ('num',)
|
2011-08-24 11:51:33 +08:00
|
|
|
|
2011-10-14 02:04:12 +08:00
|
|
|
class UnicodeReferenceModel(models.Model):
|
2012-06-08 00:08:47 +08:00
|
|
|
others = models.ManyToManyField("UnicodeReferenceModel")
|
2011-08-24 11:51:33 +08:00
|
|
|
|