📜  modelform 预填充数据 - C 编程语言代码示例

📅  最后修改于: 2022-03-11 15:04:40.586000             🧑  作者: Mango

代码示例1
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})