我想创建一个Django Group模型,其成员位于Django Person Model中...... Person实例只能出现在特定数量的组中......并且一个组只能容纳特定数量的人员实例< / p>
答案 0 :(得分:0)
尝试将人员添加到群组时执行检查。类似的东西:
class Group(models.Model):
def add_person(self, person):
if person.groups.count() > max_groups_per_person:
raise ValidationError("Can't add a person to more than %s groups" % max_groups_per_person)
if self.people.count() = max_people_per_group:
raise ValidationError("Can't add more than %s people to the group" % max_people_per_group)