Answer the question
In order to leave comments, you need to log in
How can I make a mechanism in Django whereby through the combined forms it is possible to change the values of several records at once?
The point is. There is a settings model:
class Setting(models.Model):
title = models.CharField(max_length=100, unique=True)
slug = models.CharField(max_length=30, unique=True, blank=False)
value = models.CharField(max_length=150, blank=False)
def __str__(self):
return self.title
By classic, I mean: List output, where there is a button opposite each item, by clicking on which you can edit one of the list values on a separate page. Well, somewhere in the same place above the list there will be an "add" button, and also opposite each item there will be a "delete" button
Answer the question
In order to leave comments, you need to log in
If it's a good idea to implement this in a regular Django admin, then ModelAdmin.list_editable
might be the solution . This attribute has been in jung for a long time. And once I even used it.
There is 1 pitfall, at least 3 years ago it definitely was: if more than 1 person changed data in the admin panel of the same model, then the data could be unpredictably lost and / or changed.
After digging into the sources then, I found out that this is due to the fact that when saving the edited data, djanga relies on the relative position of the object (!) in the queriset (!!) at the current moment !!!
That is, popularly speaking: do not "save the Super Item value in the title field of the instance id=345 of the MyModel model", but "save the Super Item value in the title field of the instance, which is in the current querise MyModel.objects.filter(category="Items ") on page #2 is in the 14th position".
And at first it may seem logical, they say, the classic case - the same data is changed by 2 or more people, of course you can get overwritten, but if only! Even just by adding a new object of this model, and not even from the admin panel, you can easily violate this relative "addressing".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question