Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 填充下拉菜单django modelform_Python_Django_Dynamic_Drop Down Menu_Populate - Fatal编程技术网

Python 填充下拉菜单django modelform

Python 填充下拉菜单django modelform,python,django,dynamic,drop-down-menu,populate,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(mo

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)
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
    })
view.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)
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
    })
我只是试图从模型类的数据库列
IndustryChoice
填充
Industry
的值:
Industries
。 我做错了什么?有人能帮忙吗

我收到错误消息:

name 'homepagelaunch_industries' is not defined

谢谢

您遇到了什么问题/错误?很抱歉,我用错误更新了问题。我想您没有在
forms.py
中导入您的型号
homepagelaunch\u industries
,我尝试过这样做,但似乎没有解决问题。它仍然告诉我:
名称“homepagelaunch\u industries”未定义
。我更新了上面的代码。你能发布你的
表单吗?