I want to display the level of the category that the product belongs to, in the admin page for the object. snipped a lot fo the unimportant fields out of the display below.
class Category(models.Model):
name = models.CharField(max_length=50, default=False)
level = models.IntegerField(help_text="1, 2 ,3 or 4")
class Product(models.Model):
category = models.ForeignKey(Category)
name = models.CharField(max_length=100)
prepopulated_fields = {'slug': ('name',)}
fieldsets = [
('Product Info',{'fields': ['name', 'slug','partno','description']}),
('Categorisation',{'fields': ['brand','category']}),
obviously i've tried a little to get this working and googled a lot, but i've found reference to list_filter lots, but nothing about just showing the field. best guess was
'category__level'
anyone know the right way to do this?
In your admin.py file
Try this.............
The simplest way is to put the
level
of theCategory
into the__unicode__
method:So the select box will show it.
Define a method on the ModelAdmin class which returns the value of the related field, and include that in
list_display
.