Reputation: 105
I am new to Django and still learning, I have created a database and some models but I got stuck with meaningful labels in Django Admin. This is the model:
class Product(models.Model):
product_id = models.AutoField(primary_key=True)
product_name = models.CharField(max_length= 50)
brand_name = models.CharField(max_length = 20)
category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True)
min_order = models.IntegerField()
max_order = models.IntegerField()
units = models.IntegerField()
quantity = models.ForeignKey(Quantity, on_delete=models.SET_NULL, null=True)
objects = ProductManager()
class Meta:
verbose_name = "Product"
verbose_name_plural = 'Products'
I want Product object (3) to be replaced byt the product_name. Thank you in advance!
Upvotes: 1
Views: 132
Reputation: 476614
You can override the __str__
method [python-doc] and return the product_name
instead:
class Product(models.Model):
# …
def __str__(self):
return self.product_name
Upvotes: 1