我有这个form.py
:
class specForm(ModelForm):
a = Doctors_list.objects.values_list('specialty', flat=True)
specialty = forms.ModelChoiceField(queryset=a)
class Meta:
model = Doctors_list
这views.py
:
from django.shortcuts import render_to_response
from testApp.forms import specForm
def specForm (request):
if request.method == 'POST':
form = specForm(request.POST)
if form.is_valid():
form.save()
else:
form = specForm()
return render_to_response('hello.html', {'form':form})
当我运行它时,我得到以下错误:specForm() takes exactly 1 argument (0 given)
,我想这是因为它认为form
无效,为什么?我该如何解决?
我的模型.py:
class Doctors_list(models.Model):
name = models.CharField(max_length=30)
specialty = models.CharField(max_length=15)
hp_id = models.ManyToManyField(Health_plan)
location = models.CharField(max_length=15)
def __unicode__(self):
return self.name
任何帮助表示赞赏