Problem
I have a question on how to save in editable listviews in the django-admin. I use django 1.11 with python 3.6.
Suppose I have a list of 100-200 Events in a model. In order to bulk edit a boolean field for all entries, I register the model in admin-view as editable list (see code below).
For convenience, I slice the task and display 30 entries per page by using the pagination. If I switch to the next page without pressing the save button, the changes will be lost.
Now: how can I prevent loss of my input? Is there a django method to save automatically? I can imagine three ways, but I don't know how to implement it in django.
- Instant save for the respective entry, when its checkbox is checked.
- Hook on the pagination buttons: When I press any page number, the changes are saved.
- A Popup with warning or save button, when I leave the page without having saved.
Has anybody a suggestion or code snippets for any of the three ways? Or a suggestion for different approach?
Thank you!
Minimal Example:
from django.db import models
from django.contrib import admin
class Event(models.Model):
name = models.CharField(max_length=30)
description = models.CharField(max_length=30)
relevant = models.BooleanField(default=False)
...
def __str__(self):
return '%s %s' % (self.name, description)
class Event_Admin(admin.ModelAdmin):
list_display = ('name', 'description', 'relevant')
list_editable = ('relevant')
list_per_page = 30
admin.site.register(Event, Event_Admin)