How to make recursive ManyToManyField relationships that have extra fields symmetrical in Django?

前端 未结 5 751
后悔当初
后悔当初 2020-12-18 07:53
class Food_Tag(models.Model):
    name = models.CharField(max_length=200)
    related_tags = models.ManyToManyField(\'self\', blank=True, symmetrical=False, through=         


        
5条回答
  •  悲&欢浪女
    2020-12-18 08:30

    As mentioned in the docs:

    • When defining a many-to-many relationship from a model to itself, using an intermediary model, you must use symmetrical=False (see the model field reference).

    Thus, it is not (yet?) possible to have a symmetrical, recursive many-to-many relationship with extra fields, in Django. It's a "pick two" sorta deal.

提交回复
热议问题