Django m2m自包含

设计一个group,可以包含user也可以包含group。user和group都可以被多个group包含。

class Group(models.Model):
users = models.ManyToManyField(User)
groups = models.ManyToManyField('self')

update: ManyToMany对象有一个symmetrical的参数,当为True时的意思是对象间有互相拥有的关系,是双向的,反之为False时就是单向的。

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.