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