我正在尝试解决这个问题。在那里,我正在尝试使用带有过滤器的 django-tables2 分页。问题是过滤器不会持续分页。但是,由于分页链接使用 GET 方法,我试图my_filter
在查询字符串中填充“当前”值。
我的想法是:当index
视图被调用时,我可以解包 my_filter 的当前值并将过滤器重新应用于我的表。
我创建了一个包含一些选项的下拉字段:
MY_CHOICES = (
('Apple', 'Apple'),
('Ball', 'Ball'),
('Cat', 'Cat'),
)
我的模型:
class TestModel(models.Model):
my_choices = models.CharField(max_length=20, choices=MY_CHOICES, default="", verbose_name="Choices")
我的表格:
class TestFilter(forms.ModelForm):
class Meta:
model = TestOrder
fields = ('my_choices',)
我的观点:
def index(request):
if request.method == "POST":
my_filter = TestFilter(request.POST)
my_selection = my_filter.cleaned_data['my_choices']
my_filter = TestFilter(request.POST)
else:
my_filter = TestFilter()
return render(request, 'my_app/index.html', {'my_filter': my_filter})
有没有办法获得my_filter
下拉的“当前”值?换句话说,是否可以在页面完成加载后(即当前选择的值my_filter
)检索网页上显示的数据?