0

表格.py

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

模型.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)

视图.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

谢谢!

4

0 回答 0