I think this is best understood with an example:
Pizzas and Toppings have a many to many relationship. I want to display a Pizza's toppings in a TabularInline.
class ToppingInlineAdmin(admin.TabularInline):
model = Pizza.toppings.through
fields = ('topping',)
extra = 0
if not model.topping.count():
classes = ['collapse']
As you can see, I only want to collapse the tabular inline if there are no toppings on the pizza.
The code model.topping.count() does not work though. The error is:
AttributeError: 'ForwardManyToOneDescriptor' object has no attribute 'count'
Do you know how I can accomplish if no toppings on the pizza, collapse the tabular inline?
Thank you.