如何将ajax添加到django管理中
我想让 django 管理界面的某些方面更加流畅,无需刷新。
例如,我有这个 ReportAdmin(admin.ModelAdmin) 类,它有一个 list_editable 属性,允许用户直接编辑报告视图列表上的特定字段,而不是单击每个报告并在那里编辑它。但是,我希望每个编辑字段下有一个按钮,这样当用户完成编辑特定单元格时,他只需单击该按钮即可使用ajax保存该单元格(如果不可能,是否可以使用ajax保存而是保留整个表单?只需保留更改列表并仅保存预期的更改)。
如果有人对如何实现这一目标有任何想法/资源,我们将不胜感激!
贾森
I'd like to make some aspects of django admin interface a bit more fluid without refreshes.
For example, I have this ReportAdmin(admin.ModelAdmin) class, which has a list_editable property that will allow user to edit the specific fields right on the list of reports view rather than clicking into each report and edit it there. However, i'd like a button under each edited field such that when the user finishes editing a particular cell, he can just click on that button to use ajax to save that cell (if not possible, is it possible to use ajax to save the entire form instead? Just keep a list of changes and save only the intended change).
If anyone have any idea/resources on how to accomplish this, it would be much appreciated!
Jason
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用其 媒体将 JS 代码添加到管理对象类。您可以在那里定义通过 Ajax 提交更改的函数。
You can add JS code to Admin objects using its Media class. There you can probably define functions to submit changes through Ajax.
管理员使用formsets以多种形式显示数据,并使用
formset.save()
检查formset.changed_forms< /code> 保存之前。因此,只发生必要的数据库写入。并非每个数据库条目都会被重写。
Admin uses formsets to display dtata in multiple forms and
formset.save()
checks forformset.changed_forms
before saving. So, only necessary db writes happen. Not every db entry is re-written.老问题,但我在谷歌搜索时发现了它。尝试 https://github.com/sjrd/django-ajax-selects
Old question, but I found it when googling. Try https://github.com/sjrd/django-ajax-selects