I need to define a Meeting model which includes an organiser and a number of participants. All participants are derived from the standard User in auth module.
from django.db import models
from django.contrib.auth.models import User
class Meeting(models.Model):
organizer=models.ForeignKey(User)
participants=models.ManyToManyField(User)
However, when running syncdb, the I got the following error
Error: One or more models did not validate: hub.meeting: Accessor for
field ‘organizer’ clashes with related m2m field ‘User.meeting_set’.
Add a related_name argument to the definition for ‘organizer’.
hub.meeting: Accessor for m2m field ‘participants’ clashes with
related field ‘User.meeting_set’. Add a related_name argument to the
definition for ‘participants’.
Can anyone help me to solve this?
If you have a user object and you want to follow the relationship backwards to find either the meetings that user is an organizer of or meetings that the user is a participant of, you need to specifically name a ‘related_name’ field on the model to distinguish them. Now you can follow the relationship backwards like so: