你好的人,這裏是我的代碼在Django的初始值形成
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被調用,有沒有辦法解決這個問題?
是什麼你的看法? – Rohan 2013-03-07 07:22:46
嗨Rohan,問題更新,,,,請檢查,,, – Friend 2013-03-07 07:24:39