I am trying to display a brand of a bike in my django admin panel. I have managed to display the title, but I am struggling with the brand.
Here's my models.py:
class Bike(models.Model):
item = models.OneToOneField(Item, on_delete=models.CASCADE)
category = models.ManyToManyField(Category, blank=True)
image = models.ImageField(upload_to='bikes')
brand = models.ManyToManyField(Brand, null=True)
def __str__(self):
return self.item.title
class Brand(models.Model):
name = models.CharField(max_length=20)
def __str__(self):
return self.name
I have tried that:
def __str__(self):
return self.brand.name
But nothing is displaying then. Any ideas how to display the self.item.title and brand name at the same time?