7
This part of the form deals with editing the ManyToManyField
. It will use the __str__
of the model that is referenced.
In order to thus change the textual representation, you need to implement the __str__
of the Course
model, like:
class Course(models.Model): # Course model, not Person
name = models.CharField(max_length=128)
def __str__(self):
return self.name
Setting the __str__
of a person to self.course.name
does not seem correct, since you probably do not want to represent a Person
by the name of its courses. Furthermore since this is a ManyToManyField
, it will not work anyway.
Note: usually the name of
ManyToManyField
s is plural, socourses
, instead ofcourse
, since it is basically a collection ofCourse
s, not a singleCourse
.
Source:stackexchange.com