1👍
✅
The initial
argument and the instance
argument in your call to SettingsForm()
serve the exact same purpose, because you are using the fields of the instance
individually in each field of initial
.
The save() method is not working because you need to populate the form with data from request.POST
.
This view should work:
def settings(request):
settingsObj = Settings.objects.get(id=1)
if request.POST:
form = SettingsForm(request.POST, instance=settingsObj)
if form.is_valid():
form.save()
else:
form = SettingsForm(instance=settingsObj)
context = { ..., 'form': form, ... }
return render(request, 'template-address', context)
Source:stackexchange.com