我正在使用django-filter包,我有一些字段,我想依赖于另一个字段,如我有字段name
和字段car
,如果我在name
过滤器中选择名称Michael,过滤器car
将只显示Michael拥有的汽车
这看起来是个大问题,我不知道该怎么解决
filters.py
import django_filters
from django_filters import DateTimeFromToRangeFilter
from django.db.models import Q
from common.filters import CustomDateRangeWidget
from common.models import CounterParty, ObjectList
from .models import OpenPointList
class OpenPointFilter(django_filters.FilterSet):
"""
Django-filter class to filter OpenPointList model by date, CounterParty name and Object name
"""
CHOICES = (
('Closed', 'Closed'),
('Open', 'Open')
)
status = django_filters.ChoiceFilter(choices=CHOICES)
category_choice = django_filters.ModelChoiceFilter(label='Категория',
queryset=OpenPointList.objects.values_list('category',
flat=True).distinct())
category = django_filters.CharFilter(method='custom_category_filter')
class Meta:
model = OpenPointList
fields = (
'open_point_object',
'status',
'category',
)
1条答案
按热度按时间odopli941#
你必须使用 AJAX 来实现这一点,就像当你选择一个下拉列表时,你必须调用Ajax,作为响应,你必须在另一个下拉列表中设置选项,等等。