raw_id_fields for modelforms

后端 未结 3 731
挽巷
挽巷 2021-01-01 22:52

I have a modelform which has one field that is a ForeignKey value to a model which as 40,000 rows. The default modelform tries to create a select box with 40,000 options, wh

3条回答
  •  攒了一身酷
    2021-01-01 23:09

    You need to change the widget for the base field, not the field type. I think this would work:

    class OpBaseForm(ModelForm):
        base = forms.ModelChoiceField(queryset=Base.objects.all(), 
                                      widget=forms.TextInput)
    
        class Meta:
            model = OpBase
            ... etc... 
    

提交回复
热议问题