I have two models:
class Customer(models.Model):
(...)
class CustomerMemo(models.Model):
(...)
customer = models.ForeignKey(Customer)
text = models.TextField()
And in my admin.py
class MemoInline(admin.StackedInline):
model = CustomerMemo
class Customer(admin.ModelAdmin):
(...)
inlines = (MemoInline,)
I want to make autosave for these inline fields.
I think there should be ajax request every 30 seconds.
But now there two questons:
-
How to make ajax request which gets requred data from admin page?
-
How would be better to add admin custom view which handle this ajax request?
I’ve read about dajax, but I can’t get how it could help me with my task.
Thanks
Redefine admin template and add a JS with some function which will gather form data with
$(form).serialize()and make an ajax POST to the server. URL for POST can be admin page itself (if you don’t mind overwriting the object) or you can write your own view with necesssary form and formsets. Maybe you’ll also need to add value of the “Save” button to POST load.