[Answer]-Django admin, show 2 or more attributes in a field

1πŸ‘

βœ…

On the Course model you can define the __unicode__(self): method to interpolate two attributes together. So, in your case you could combine the name of the course and the attendance.

That would look something like this:

class Course(models.Model):
    name = models.CharField(max_length=100)
    attendance = models.CharField(max_length=100)

    def __unicode__(self):
        return "%s (%s)" % (self.name, self.attendance)

Then the string representation of that course will be the name of the course followed by the attendance in parenthesis.

An example of this can be found in the documentation.

πŸ‘€Kinsa

Leave a comment