我有这个错误:
appname_mymodel.user_id 不能为 NULL
def form_view(request):
user = request.user
f_form = FForm(request.POST or None, request.FILES or None)
if request.method == "POST":
if f_form.is_valid():
f_form.user = user
f_form.save()
return HttpResponseRedirect('/thanks/')
return render_to_response('upload.html', {'f_form': f_form}, context_instance=RequestContext(request))
表格.py:
class FForm(ModelForm):
class Meta:
model = MyModel
exclude =['user']
如何保存当前登录用户?