How to add ajax to django admin

I want some aspects of the django admin interface to be a little more fluid without updates.

For example, I have this ReportAdmin class (admin.ModelAdmin), which has a list_editable property that allows the user to edit certain fields directly in the list of report views, rather than clicking on each report and editing it there. However, I would like the button below each edited field so that when the user finishes editing a specific cell, he can simply click on this button to use ajax to save that cell (if this is not possible, can ajax be used to save the whole form instead: just save the list of changes and save only the proposed change).

If anyone has any ideas / resources on how to do this would be very helpful!

Jason

+3
source share
3 answers

You can add JS code to Admin objects using the media class . There you can probably define functions for sending changes through Ajax.

+2
source

Is it possible to use ajax to save the whole form? Just save the list of changes and save only the planned changes.

The administrator uses forms to display dtata in several forms and formset.save()checks for formset.changed_formsbefore saving. Thus, only the necessary db entries occur. Not every db record is overwritten.

0

Source: https://habr.com/ru/post/1758999/


All Articles