Python 使用表中的字段作为条件创建ManyToManyField
这就是我想要实现的目标:Python 使用表中的字段作为条件创建ManyToManyField,python,django,jointable,manytomanyfield,Python,Django,Jointable,Manytomanyfield,这就是我想要实现的目标: class Event(Model): attendees = ManyToManyField(User, through='Involvement', related_name='attended_events') interested_users = ManyToManyField(User, through='Involvement', related_name='interested_in_events') organizers = Ma
class Event(Model):
attendees = ManyToManyField(User, through='Involvement', related_name='attended_events')
interested_users = ManyToManyField(User, through='Involvement', related_name='interested_in_events')
organizers = ManyToManyField(User, through='Involvement', related_name='organized_events')
class Involvement(Model):
event = ForeignKey(Event, CASCADE)
user = ForeignKey(User, CASCADE)
involvement = CharField(choices=(('INTERESTED', 'Interested'), ('ATTENDED', 'Attended'), ('ORGANIZED', 'Organized')))
我收到的错误是:
The model has three identical many-to-many relations through the intermediate model 'app.ActivityInvolvement'.
我知道
limit\u choices\u to
在很多领域都不起作用,如果不创建具有相同结构的3个直通表,我该如何实现这一点?为什么需要直通表?为什么没有三个完全独立的m2m字段?也许会有帮助。