javascript - Select2 - 不显示/删除初始值
问题描述
我django-filter
用于过滤查询Article
集。Article
有一个字段locations
:
locations = models.ManyToManyField('locations.Location', related_name='articles')
Articles
我按字段过滤locations
,作为小部件,我使用django-autocomplete-light
小部件Select2Multiple
。
class ArticleFilter(django_filters.FilterSet):
from locations.models import Location
...
locations = django_filters.ModelMultipleChoiceFilter(method='locations_filter',queryset=Location.objects.all(),label='Lokality')
...
class Meta:
model = Article
fields = ['locations','title','price_lte','price_gte','price_currency'
]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# HERE I SPECIFY THE DAL WIDGET
self.form.fields['locations'].widget = autocomplete.Select2Multiple(url="locations:locations_autocomplete")
当我单击提交时,它会正确显示过滤结果,URL 查询字符串包含所有过滤属性,包括例如locations=45
,但它没有显示location
withid=45
作为locations
字段的初始值。
奇怪的是,如果我删除小部件,我可以看到原来,有初始值:
只是Select2
没有显示它,并且位置的值是undefinfed
.
我在 raw 上使用相同的方法django.forms
,它可以正常工作。首字母也是。
你知道问题出在哪里吗?
解决方案
推荐阅读
- java - 如何从 ASCII 转换为字符串
- bash - Userdel bash脚本问题
- c++ - 从模板方法通过迭代器返回集合
- excel - 加快数组循环vba Excel
- cryptography - .Net Standard 2.0 RSA.ExportParameters(bool) 在 Linux 上不起作用
- scala - 带有 sbt 项目的 Jenkins 管道
- c - 如何在程序中使用 pam_time?
- django - Django 动态模型.FileField 存储
- .htaccess - RewriteEngine - 如何忽略对已经存在的文件夹的请求
- php - Laravel - 在多个单独的代码库之间共享功能