django-filter:使用LinkWidget为AllValuesFilter添加“All”过滤器选项

时间:2017-05-11 13:20:39

标签: django django-filter wagtail

在多对多字段中使用AllValuesFilter过滤LinkWidget并通过All显示此内容,我没有获得list_filter过滤器选项,因为与django admin Page

我发现了django-filter以及其他各种相关问题,但我没有得到解决方案......

在这个特定情况下,我正在过滤Django Add Any & None Handling to ChoiceFilter (and subclasses) # models.py # wagtail imports # ... # modelcluster imports, eg. # from modelcluster.fields import ParentalKey, ParentalManyToManyField class CategoryRegion(models.Model): title = models.CharField(max_length=200,) class NewsPage(Page): categories_region = ParentalManyToManyField( "core.CategoryRegion", blank=True, ) 模型的类别:

# filters.py

import django_filters
from django_filters.widgets import LinkWidget

class NewsFilter(django_filters.FilterSet):

    categories_region = django_filters.AllValuesFilter(
        name="categories_region__title", 
        label="Categories: Region",
        widget=LinkWidget(),
    )

    class Meta:
        model = NewsPage
        fields = ['categories_region',]

-

@echo off
setlocal EnableDelayedExpansion

rem Initialize "i" variable with the desired number of digits as zeros
set i=1000

rem Process the files in creation date-time order
for /F "delims=" %%a in ('dir /A-D /OD /B *.tif') do (

   rem Increment the number: "1001"...
   set /A i+=1

   rem Omit first digit in number: "1", use the rest: "001"...
   ren "%%a" "image(!i:~1!).tif"

)

任何提示?

1 个答案:

答案 0 :(得分:2)

bug .ddr其中AllValuesFilter没有全部/任何选项。 #680应该解决问题,但它目前尚未合并。在此期间,您应该能够为PR安装相关分支,或者创建一个自定义子类,用于添加" All"选项。类似的东西:

class ActuallyAllValuesFilter(django_filters.AllValuesFilter):

    @property
    def field(self):
        f = super(ActuallyAllValuesFilter, self).field
        f.choices = [('', 'All')] + f.choices
        return f