将外部窗口小部件添加到django-filters

时间:2015-03-10 10:17:41

标签: python django django-forms django-filter

我想为用户添加一个漂亮的选择器。我使用django-filter并想添加一个库django-selector2。我有这样的东西,我认为它不能正常工作 - 它看起来是正常的选择器。

from django_select2 import *

class UserChoices(AutoModelSelect2Field):
    queryset = User.objects
    search_fields = ['word__icontains', ]


class Filter(django_filters.FilterSet):
    user = UserChoices(widget=AutoHeavySelect2Widget())
    date_from = django_filters.DateFilter(widget=DateInput(attrs={'class':'datepicker'}))
    date_to = django_filters.DateFilter(widget=DateInput(attrs={'class':'datepicker'}))

    class Meta:
        model = MyModel
        form = MyForm
        fields = ['user', 'date_from', 'date_to']

我的观点:

class Dashboard(TableFilterView):
    model = MyModel
    table_class = TableOfUsers
    template_name = "lists.html"
    context_object_name = 'obj'
    filterset_class = Filter

    def get_context_data(self, **kwargs):
        context = super(Dashboard, self).get_context_data(**kwargs)
        f = MyForm()
        context['f'] = f
        return context

在模板中我有:

{% load django_select2_tags %}
{% import_django_select2_js %}
{% import_django_select2_css %}
{% import_django_select2_js_css light=1 %}

0 个答案:

没有答案