Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 向django过滤器添加外部小部件_Python_Django_Django Forms_Django Filter - Fatal编程技术网

Python 向django过滤器添加外部小部件

Python 向django过滤器添加外部小部件,python,django,django-forms,django-filter,Python,Django,Django Forms,Django Filter,我想为用户添加一个好的选择器。我使用django过滤器,希望添加一个库django-selector2。我有这样的东西,我认为它不能正常工作-它看起来很正常 from django_select2 import * class UserChoices(AutoModelSelect2Field): queryset = User.objects search_fields = ['word__icontains', ] class Filter(django_filters

我想为用户添加一个好的选择器。我使用django过滤器,希望添加一个库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 %}