如何将ajax添加到django管理中

发布于 2024-09-13 13:33:07 字数 300 浏览 2 评论 0原文

我想让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风渺 2024-09-20 13:33:07

您可以使用其 媒体将 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.

墟烟 2024-09-20 13:33:07

是否可以使用ajax来保存整个表单?只需保留更改列表并仅保存预期的更改

管理员使用formsets以多种形式显示数据,并使用formset.save()检查formset.changed_forms< /code> 保存之前。因此,只发生必要的数据库写入。并非每个数据库条目都会被重写。

is it possible to use ajax to save the entire form instead? Just keep a list of changes and save only the intended change

Admin uses formsets to display dtata in multiple forms and formset.save() checks for formset.changed_forms before saving. So, only necessary db writes happen. Not every db entry is re-written.

回忆追雨的时光 2024-09-20 13:33:07

老问题,但我在谷歌搜索时发现了它。尝试 https://github.com/sjrd/django-ajax-selects

Old question, but I found it when googling. Try https://github.com/sjrd/django-ajax-selects

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文