Answers for "modelform prefill with data"

C
0

modelform prefill with data

from django.forms.models import model_to_dict

 user = User.objects.get(user_id=usr)  
 if request.method == 'POST':  
     form = TableForm(request.POST)  
     if form.is_valid():  
         #do something  
 else:          
     form = TableForm(initial=model_to_dict(user))  
 return render_to_response('template.html',{'form':form})
Posted by: Guest on July-25-2020

Code answers related to "modelform prefill with data"

Code answers related to "C"

Browse Popular Code Answers by Language