FurtiveFelon
FurtiveFelon

Reputation: 15166

how to add ajax onto django admin

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

Upvotes: 3

Views: 7333

Answers (3)

che
che

Reputation: 12263

You can add JS code to Admin objects using its Media class. There you can probably define functions to submit changes through Ajax.

Upvotes: 4

Jens Alm
Jens Alm

Reputation: 3057

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

Upvotes: 0

lprsd
lprsd

Reputation: 87095

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.

Upvotes: 0

Related Questions