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