Skip to content Skip to sidebar Skip to footer

Django - Checkboxselectmultiple Shows Object Representation Instead Of Object's Name

So I am trying to have a list of checkboxes of cities, but instead of showing the cities' name, it shows this: How to make it shows the name instead of City object?

Solution 1:

In your model you have to include __str__ for python3 and unicode for python 2

For example python 3:

classCity(models.Model):
    name = forms.CharField(max_length=200, default="")

    def__str__(self):
        returnself.name

Python 2

classCity(models.Model):
    name = forms.CharField(max_length=200, default="")

    def__unicode__(self):
        returnself.name

Post a Comment for "Django - Checkboxselectmultiple Shows Object Representation Instead Of Object's Name"