2006-05-02 01:31:56 +00:00
|
|
|
"""
|
2014-09-24 05:13:13 +00:00
|
|
|
Many-to-many and many-to-one relationships to the same table
|
2006-05-02 01:31:56 +00:00
|
|
|
|
2006-05-31 19:23:07 +00:00
|
|
|
Make sure to set ``related_name`` if you use relationships to the same table.
|
2006-05-02 01:31:56 +00:00
|
|
|
"""
|
|
|
|
from django.db import models
|
|
|
|
|
2011-10-13 18:04:12 +00:00
|
|
|
|
2006-05-02 01:31:56 +00:00
|
|
|
class User(models.Model):
|
2007-08-05 05:14:46 +00:00
|
|
|
username = models.CharField(max_length=20)
|
2006-05-02 01:31:56 +00:00
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2006-05-02 01:31:56 +00:00
|
|
|
class Issue(models.Model):
|
|
|
|
num = models.IntegerField()
|
2022-02-03 19:24:19 +00:00
|
|
|
cc = models.ManyToManyField(User, blank=True, related_name="test_issue_cc")
|
|
|
|
client = models.ForeignKey(User, models.CASCADE, related_name="test_issue_client")
|
2006-05-31 19:23:07 +00:00
|
|
|
|
2006-05-02 01:31:56 +00:00
|
|
|
class Meta:
|
2022-02-03 19:24:19 +00:00
|
|
|
ordering = ("num",)
|
2011-08-24 03:51:33 +00:00
|
|
|
|
2018-12-28 00:34:14 +00:00
|
|
|
def __str__(self):
|
|
|
|
return str(self.num)
|
|
|
|
|
2013-11-03 04:36:09 +00:00
|
|
|
|
2017-01-20 21:04:05 +00:00
|
|
|
class StringReferenceModel(models.Model):
|
2022-02-03 19:24:19 +00:00
|
|
|
others = models.ManyToManyField("StringReferenceModel")
|