i have 3 models, linked fks in chain this:
class customer(models.model): name = models.charfield(max_length=100) class order(models.model): name = models.charfield(max_length=100) customer = models.foreignkey( 'customer.customer', on_delete=models.protect) class task(models.model): name = models.charfield(max_length=100) order = models.foreignkey( 'order.order', on_delete=models.protect)
now, if within taskadmin, use:
list_filter = ('order__customer', )
everything works fine. if go with:
def get_list_filter(self, request): return ('order__customer', )
the page loads, click on possibile customer, bad request (400) error page appears. sounds django bug me, maybe i'm doing wrong here... hints?
i don't have enough reputation add comment, i'll write here, if not real answer.
it looks there's open ticket on topic: lookup_allowed fails consider dynamic list_filter
you can use 2 different workarounds solve problem until fixed upstream:
- in addition
get_list_filter
can definelist_filter = ('order__customer',)
, field's lookups whitelisted, if not used (because get_list_filter has precedence) you can override
lookup_allowed
way:def lookup_allowed(self, lookup, *args, **kwargs): if lookup == 'order__customer__id__exact': return true return super(taskadmin, self).lookup_allowed(lookup, *args, **kwargs)
this explicitly allows single lookup used url param.
Comments
Post a Comment