How do you refer to the fields of the respective models in the admin list_filter?

My models:

OrderInfo is individually printable, which is a many-to-one with painting, which in itself is a many-to-one with a club.

class OrderInfo(models.Model): print_ordered = models.OneToOneField(Print, blank=True) class Print(models.Model): painting = models.ForeignKey(Painting) class Painting(models.Model): club = models.ForeignKey(Club) 

In my OrderInfoAdmin, I would like to be able to sort the Club associated with it, but I cannot understand the syntax to do this.

I tried this, but it does not work:

 class OrderInfoAdmin(admin.ModelAdmin): list_filter = ['print_ordered__painting__club'] 

Any help is appreciated, thanks in advance!

+4
source share
2 answers

The list_filter command list_filter designed to filter out non-ordering. You want the ordering command to be registered here: http://docs.djangoproject.com/en/dev/ref/models/options/#ordering . This is not clear to me, although from the documentation, if the modeling Meta command allows you to order through foreign keys. (The filter() request function definitely does: http://docs.djangoproject.com/en/dev/ref/models/querysets/#order-by-fields )

I found that the administrator has some limitations that work with deeply hierarchical models. For example, you can embed a child model in a parent page, but you cannot include a grandson. In addition, by default, the list_filter command list_filter works with fields in the simulated table. In your example, you cannot filter the Print fields in the OrderInfo , for example.

+2
source

Just today, Josh VanderLinden posted a solution for this on his blog:

Relationship model and "list_display"

(Found through the Django Community )

+1
source

All Articles