My models are as follows:
class Retailer(BaseModel):
brand = models.ManyToManyField('brands.Brand',blank=True)
class Brand(BaseModel):
name = models.CharField(max_length=100, unique=True)
website = models.URLField(max_length=500, blank=True, default='')
And my admin class is as follows:
class RetailerAdmin(admin.ModelAdmin):
filter_horizontal = ('brand',)
The admin site does show the multi-select field for me, but every entry in the brand list is just shown as Brand object
, which makes no sense to me. I want every entry to be shown as the name field of that brand. What should I do?
You can just add __unicode__
(python 2) or __str__
(python 3) method to your model so it'll look like this
class Brand(BaseModel):
name = models.CharField(max_length=100, unique=True)
website = models.URLField(max_length=500, blank=True, default='')
def __unicode__(self):
return self.name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With