我有一个具有一个字段lawyersspec__lawyer_spec
的过滤器。要使用此过滤器,可以使用一种效果很好的表格,该表格可以在网站A上找到,但我想将指向此网站的链接的过滤器设置为某个值。 (即lawyersspec__lawyer_spec=2
)
filters.py
class LawyerFilter(django_filters.FilterSet):
class Meta:
model = TestPy.models.Lawyer
fields = ['lawyersspec__lawyer_spec']
def __init__(self, *args, **kwargs):
super(LawyerFilter, self).__init__(*args, **kwargs)
views.py
object_list = TestPy.models.Lawyer.objects.filter(Q(confirmed=True) & Q(is_active=True))
filter = LawyerFilter(request.GET, queryset=object_list)
template.html
{% for i, spec in specs.items %}
<a href=" {% url 'lawyer-list' %}?lawyersspec__lawyer_spec={{ i }}">{{ spec }}</a>
我该如何实现?我尝试将模板中的url设置为{% url 'lawyer-list' %}?lawyersspec__lawyer_spec=value
,但无法正常工作。我的意思是,过滤器是将表单设置为正确的形式,但结果并未过滤。
我检查了lawyersspec__lawyer_spec
是否在GET中可用,并且在那里,但是由于某些原因,筛选器未根据这些变量进行筛选。