5👍
✅
If the data for the models hasn’t been altered, the model isn’t marked as dirty, so I’m presuming the formset.save(commit=False) returns Null. But you know the data is dirty, so why not just do this:
if formset.is_valid():
for form in formset:
instance = form.instance
instance.position = pk_list.index(instance.layer.pk)
instance.save()
In other words, you just obtain the model instance from each bound form, you don’t rely on the save method to answer them.
7👍
There is another way, how to to this:
class LayerMapOptionsForm(forms.ModelForm):
def has_changed(self, *args, **kwargs):
return True
- [Django]-Django default foreign key value for users
- [Django]-Trying to avoid circular imports
- [Django]-Django 1.9: Should I avoid importing models during `django.setup()`?
- [Django]-What do I need to run Sentry inside my django site
- [Django]-Manage.py doesn't pass the argument to the command
Source:stackexchange.com