我的第一个问题是数据没有进入数据库。它没有显示任何错误,但也没有存储。我的第二个问题是我正在使用下拉列表中的查询集预先填充表单字段,但它向我显示 id(主键),我想显示其他字段。我该怎么做?
我的观点
def payment(request):
#form = jobpostForm_first()
#country_list = Country.objects.all()
if request.POST:
form = jobpostForm_detail(request.POST)
if form.is_valid():
if '_Submit' in request.POST:
form.save()
return HttpResponseRedirect('/thanks/')
else:
form = jobpostForm_detail()
#form.fields['country'].queryset = Country.objects.all()
c = {}
c.update(csrf(request))
return render_to_response('portal/display.html',{
'form':form
},context_instance=RequestContext(request))
我的模型:
class jobpostForm_detail(ModelForm):
class Meta:
model = payment_detail
fields = ('payment_type','country')
def __init__(self, *args, **kwargs):
super(jobpostForm_detail, self).__init__(*args, **kwargs)
self.fields['country'].queryset = Country.objects.all()
self.fields['payment_type'].queryset = Payment_types.objects.all()
self.helper = FormHelper()
self.helper.form_class = 'horizontal-form'
self.helper.form_id = 'id-jobpostform'
self.helper.form_class = 'blueForms'
self.helper.form_method = 'post'
self.helper.add_input(Submit('submit_addcontent', 'Pay'))
super(jobpostForm_detail, self).__init__(*args, **kwargs)
我的模板:
<form method="post" action="/portal/next/post/" class="blueForms" id="id-jobpostform">
{% csrf_token %}
{% crispy form %}
</form>