Задать вопрос

Тел: +7 965 3737 888

433

Просмотров

2

Ответов

ForeignKey filterspec

Unfortunately, it is not possible currently to use foreign keys in list filter of the admin website. list_filter=['city__country'] doesn't work.

This filter spec tries to workaround this problem.

It is also possible to have 2 filters for a foreign-key field but it requires to add a dummy field to the model. Set the fk_filterspec dictionnary on this dummy field and add 'fk':'real-field' to the dict.

Вопрос полезен? Да0/Нет0
file_4347.py(3.1Кб)
None

Ответы (2):

Ответdaiana:10.05.2011
Ответ полезен? Да0/Нет0

@gmandx

Thanks for your help! I had the same problem and this solved it.

Ответgmandx:24.04.2011
Ответ полезен? Да0/Нет0

I had to change the __init__() method to make it work with Django 1.3

    def __init__(self, f, request, params, model, *args, **kwargs):
        super(FkFilterSpec, self).__init__(f, request, params, model, *args, **kwargs)

It was giving errors because an unexpected field_path keyword argument.