Django: list_filter and foreign key fields

前端 未结 6 1832
野性不改
野性不改 2021-02-07 00:54

Django doesn\'t support getting foreign key values from list_display or list_filter (e.g foo__bar). I know you can create a module method as a workaround for list_display, but h

6条回答
  •  情深已故
    2021-02-07 01:26

    I ran into the same problem and really needed a solution. I have a workaround that lets you create a filter on a FK related model property. You can even traverse more than one FK relationship. It creates a new FilterSpec subclass that subclasses the default RelatedFilterSpec used to give you a filter on a ForeignKey field.

    See http://djangosnippets.org/snippets/2260/

提交回复
热议问题