Django内联表单,可一次编辑多个相关记录 - 正确的方法? [英] Django Inline formset for editing multiple related records at once - the right way to go?

查看:873
本文介绍了Django内联表单,可一次编辑多个相关记录 - 正确的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用内联表单时,如何进行分页?我使用django 1.1。
我现在的情况是,用户需要能够快速方便地编辑相关对象(这就是为什么我认为我应该使用内联表单)。然而,可以有一百多个对象编辑,这使得一个非常大的表单,所以分页是有意义的。

When using inline formsets, how does one do paging? I'm using django 1.1. The situation I'm in, is that the user needs to be able to edit the related objects quickly and easily (which is why I think I should be using an inline formset). However, there can be a more than a hundred objects to edit, which makes a pretty large formset, so paging would make sense.

有没有更好的方式来做这个?

Is there a better way to be doing this?

感谢
Bert

Thanks Bert

推荐答案

不幸的是,我无法使用分页来处理formets。

Unfortunately I couldn't get paging to work with formsets.

扩展BaseInlineFormSet并更改了get_queryset方法,以仅返回需要编辑的对象的一部分,并对返回的最大对象数设置限制。因此,当用户想要编辑相关对象时,它们只能一次编辑设定数量的对象,例如20可能60.当用户完成编辑前20,并提交表单时,将显示接下来的20个。

Instead I extended BaseInlineFormSet and changed the get_queryset method to return only a subset of the objects that were needed to be edited and set a limit on the maximum number of objects returned. So when the user wants to edit related objects, they can only edit a set number of objects at a time e.g. 20 of the possible 60.When the user has completed editing the first 20, and submits the form, the next 20 will be displayed.

这篇关于Django内联表单,可一次编辑多个相关记录 - 正确的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆