填充下拉django模型

时间:2013-08-24 20:19:29

标签: python django dynamic drop-down-menu populate

forms.py

class BetaUser(ModelForm):
    Industry = forms.ModelChoiceField(queryset = homepagelaunch_industries.objects.all(), initial=1)
        class Meta:
            model = BetaUsers
            fields = ['Industry']

model.py

class BetaUsers(models.Model):
    Industry = models.CharField(verbose_name="Industry",max_length=100)
    #Industry = forms.ModelChoiceField(verbose_name="Industry", queryset=Indus.objects.all())

class Industries(models.Model):
    IndustryChoice = models.CharField(max_length=60)

view.py

def BetaUserDisplayForm(request):
    BetaUserGatherForm = BetaUser(request.POST or None)
    if request.method == 'POST':
        if BetaUserGatherForm.is_valid():
            BetaUserIndustry = BetaUserGatherForm.cleaned_data['Industry']
            BetaUserGatherForm.save()
            try:
                return HttpResponseRedirect('/BetaUserThankYou/')
            except:
                raise ('Invalid request')
        else:
            BetaUserGatherForm = BetaUser()

    return render(request, 'apage.html', {
        'BetaUserGatherForm': BetaUserGatherForm
    })

我只是尝试从模型类Industry填充数据库列IndustryChoiceIndustries的值。 我究竟做错了什么?有人可以帮忙吗?

我得到错误:

name 'homepagelaunch_industries' is not defined

谢谢!

0 个答案:

没有答案