[Fixed]-How to look over all form fields provided and updating the model

1👍

You can do like:

from django.shortcuts import get_object_or_404

if request.method == 'POST':
    if account_id::
        account = get_object_or_404(accounts, pk=account_id)
        form = MyModelForm(request.POST,request.FILES, instance=account)
        if form.is_valid():
            ...
            form.save()
            return HttpResponseRedirect('/dashboard/accounts/')
    else:
        form = MyModelForm(request.POST, request.FILES)
        if form.is_valid():
            if request.POST.get("name").lower() == 'new':
                raise Http404("New account name may not be named NEW.")
            form.save()

Learn more about forms here

Leave a comment