modelform prefill with data
snippet in c

modelform prefill with data

user3538

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})