Django FormView和分页 [英] Django FormView and pagination
本文介绍了Django FormView和分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果表单有效,我使用django的FormView返回一组对象。
我的视图函数是这样的:
I am using django's FormView to return set of objects if form is valid. My view function is as such:
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上分页。我的问题是我无法弄清楚如何适应分页在这个方案的事情?
I want to paginate on contrib_images.My problem is i cant figure out how to fit pagination in this scheme of things?
推荐答案
Django提供了几个类,可以帮助您管理分页数据 - 也就是说,跨多个页面分割的数据, /下一步链接。这些类生活在 django / core / paginator.py
Django provides a few classes that help you manage paginated data – that is, data that’s split across several pages, with "Previous/Next" links. These classes live in django/core/paginator.py
这篇关于Django FormView和分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文