|
|
@ -49,8 +49,31 @@ def userinfo_model_form(request): |
|
|
|
print(f.clean()) |
|
|
|
print(f.clean()) |
|
|
|
print(f.cleaned_data['username']) |
|
|
|
print(f.cleaned_data['username']) |
|
|
|
print(f.data) |
|
|
|
print(f.data) |
|
|
|
|
|
|
|
f.save() |
|
|
|
else: |
|
|
|
else: |
|
|
|
errors = f.errors |
|
|
|
errors = f.errors |
|
|
|
print(errors) |
|
|
|
print(errors) |
|
|
|
return render(request, 'form_demo/userinfomodels.html', {'form_obj': f, 'errors': errors}) |
|
|
|
return render(request, 'form_demo/userinfomodels.html', {'form_obj': f, 'errors': errors}) |
|
|
|
return render(request, 'form_demo/userinfomodels.html', {'form_obj': f}) |
|
|
|
return render(request, 'form_demo/userinfomodels.html', {'form_obj': f}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def userinfo_model_from_save(request): |
|
|
|
|
|
|
|
if request.method == 'GET': |
|
|
|
|
|
|
|
a = UserBaseInfo.objects.get(id=1) |
|
|
|
|
|
|
|
myform = UserInfoModelForm(instance=a) |
|
|
|
|
|
|
|
return render(request, 'form_demo/userinfomodels.html', {'form_obj': myform}) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
f = UserInfoModelForm(request.POST) |
|
|
|
|
|
|
|
if f.is_valid(): |
|
|
|
|
|
|
|
# 直接保存 |
|
|
|
|
|
|
|
# f.save() |
|
|
|
|
|
|
|
# 延时保存 |
|
|
|
|
|
|
|
user = f.save(commit=False) |
|
|
|
|
|
|
|
# user.username = request.username |
|
|
|
|
|
|
|
print(user) |
|
|
|
|
|
|
|
user.save() |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
errors = f.errors |
|
|
|
|
|
|
|
print(errors) |
|
|
|
|
|
|
|
return render(request, 'form_demo/userinfomodels.html', {'form_obj': f, 'errors': errors}) |
|
|
|
|
|
|
|
return render(request, 'form_demo/userinfomodels.html', {'form_obj': f}) |
|
|
|