[Answered ]-Modelform not saving data even tho it is being executed

1👍

Using instance=request.user makes no sense. This means you are going to edit the logged in user record. But that is not a DadoDB object, so you will set attributes on the logged in user, and when saving the user, there will be no changes, not even to that suer object, since the user has no fields like cor, ano, etc.

@login_required
def InserirDado(request):
    if request.method == 'POST':
        # no instance=request.user ↓
        form = InsiraDadosForm(request.POST)
        if form.is_valid():
            form.instance.autor = request.user
            form.save()
            print(request.POST)
            messages.success(request, f'Seus dados foram inseridos com sucesso!')
            return redirect('dado-InserirDado')
    else:
       form = InsiraDadosForm()
    return render(request, 'dado/inserirdado.html', {'form': form})

Leave a comment