Monday, August 15, 2011

showing an attribute of a foreign key in admin

copied and pasted from stackoverflow, since i didnt get an answer in a
week and i just can't believe its not possible.

I want to display the Level of the Category that the product belongs
to, in the admin page for the Product. snipped a lot of 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' inside the fieldset as a field, but that didnt work.

anyone know the right way to do this?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate