2

I'm stuck on using django's admin feature.

How do I use admin's list_filter for the pizza from toppingsAdmin?

For example, I have these models,
class Topping(models.Model):
    # ...

class Pizza(models.Model):
    # ...
    toppings = models.ManyToManyField(Topping)


From PizzaAdmin, I can call list_filter = ('toppings',)

But, How do I call pizzas from toppingsAdmin. Seems like list_filter = ('pizzas',) does not work, because it doesn't have it as variable inside the Topping model.

Thank you

dting
  • 38,604
  • 10
  • 95
  • 114
DavidL
  • 1,260
  • 2
  • 17
  • 35

1 Answers1

0

Add related_name to your toppings field in Pizza model:

toppings = models.ManyToManyField(Topping, related_name='pizzas')

Now you can use the 'pizzas' in the list_filter

Sergey Golovchenko
  • 18,203
  • 15
  • 55
  • 72
  • 1
    Hm, that gives me ImproperlyConfigured error. refers to field 'pizzas' that is missing from the model. – DavidL Mar 29 '11 at 20:49