如果表单有效,我正在使用 django 的 FormView 返回对象集。
我的视图函数是这样的:
class IdeaView(FormView):
template_name = 'contributor/browse_photo.html'
def get_form_class(self):
return ContributorSearchForm
def form_valid(self, form):
cleaned_data = form.cleaned_data
filter_dict = {}
for key, value in cleaned_data.iteritems():
if key == 'colour' and cleaned_data['colour']:
filter_dict['colour_tag1'] = cleaned_data['colour']
if key == 'style' and cleaned_data['style']:
filter_dict['style_tag1'] = cleaned_data['style']
if key == 'material_type' and cleaned_data['material_type']:
filter_dict['material'] = cleaned_data['material_type']
if key == 'space' and cleaned_data['space']:
filter_dict['space_tag1'] = cleaned_data['space']
if key == 'sub_category' and cleaned_data['sub_category']:
filter_dict['space_sub_tag1'] = cleaned_data['sub_category']
contrib_images = ContributorImage.objects.filter(**filter_dict)
form = self.get_form_class()
form = form(initial=cleaned_data)
return render_to_response('contributor/browse_photo.html',
{'form':form,
'contrib_obj':contrib_images },
context_instance=RequestContext(self.request)
)
我想对 contrib_images 进行分页。我的问题是我不知道如何在这个方案中适应分页?
Django 提供了一些类来帮助您管理分页数据——即分成多个页面的数据,并带有“上一页/下一页”链接。这些班级住在django/core/paginator.py
链接到文档 https://docs.djangoproject.com/en/1.6/topics/pagination/#module-django.core.paginator
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)