大家好,这里是我的代码
class F1articles(forms.Form):
heading=forms.CharField(max_length=100)
content=forms.CharField(widget=forms.Textarea)
class F2articles(forms.Form):
country=forms.CharField(max_length=100)
work=forms.CharField(max_length=100)
这是在 Urls.py
url(r'^create/(?P<project_id>\d+)/$', FarticlesWizard.as_view([F1articles, F2articles]))
这是我的看法
class FarticlesWizard(SessionWizardView):
def done(self,form_list,**kwargs):
form_dict={}
Varticles_obj=None
for x in form_list:
form_dict=dict(form_dict.items()+x.cleaned_data.items())
if kwargs.has_key('project_id'):
Varticles_obj=Marticles.objects.get(id=kwargs['project_id'])
Varticles_obj.heading=form_dict['heading']
Varticles_obj.content=form_dict['content']
Varticles_obj.country=form_dict['country']
Varticles_obj.work=form_dict['work']
Varticles_obj.modified_on=datetime.datetime.now()
Varticles_obj.modified_by=self.request.user.username
Varticles_obj.save()
return HttpResponseRedirect('/display/')
else:
insert_db=Marticles(heading = form_dict['heading'],
content = form_dict['content'],
country=form_dict['country'],work=form_dict['work'],created_by=self.request.user)
insert_db.save()
return HttpResponseRedirect('/display/')
这可以正常工作,没有问题,但是我想在调用 url 时为表单字段设置初始值,有没有办法解决这个问题?