django "__init__takes at least 2 arguments" for dynamic drop down list function
Question: Regarding the django dynamic drop down list, I made some trials,

**If no dynamic function, it works without problem**

    
    
    from django import forms
    from django.forms import ModelForm
    from .models import input
    from result.models import result
    from django.contrib.auth.models import User,Group
    import Queue
    
    class inputform(forms.ModelForm):
    
        regionlist = forms.ModelChoiceField(queryset=result.objects.values('Region').distinct())
    
    class Meta:
        model = input
        fields = ('company', 'Region')
    

**If add the dynamic function like below, there is error of "__Init__takes at
least 2 arguments(2 given)**

    
    
    ...before are same as above....
    class inputform(forms.ModelForm):
        region = forms.ModelChoiceField(label=u'Region')
    
    
        def __init__(self,*args,**kwargs):
            super(inputform,self).__init__(*args,**kwargs)
            self.fields['region'].choices=((x.que,x.disr) for x in result.objects.values('Region').distinct())
    

......below are the same as above one...

**Traceback**

    
    
    Traceback:
    File "C:\Python27\lib\site-packages\django-1.8.3 py2.7.egg\django\core\handlers\base.py" in get_response
      132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\views\decorators\csrf.py" in wrapped_view
    58.         return view_func(*args, **kwargs)
    File "C:\Users\user\XXX\inputform\views.py" in input
    13.         form = inputform() #??????
    File "C:\Users\user\Desktop\XXX\inputform\forms.py" in __init__
    22.         self.fields['region'].choices=((x.que,x.disr) for x in result.objects.values('Region').distinct())
    File "C:\Python27\lib\site-packages\django-1.8.3-py2.7.egg\django\forms\fields.py" in _set_choices
    851.             value = list(value)
    File "C:\Users\user\Desktop\XXX\inputform\forms.py" in <genexpr>
    22.         self.fields['region'].choices=((x.que,x.disr) for x in result.objects.values('Region').distinct())
    
    Exception Type: AttributeError at /input
    Exception Value: 'dict' object has no attribute 'que'
    

**Second Trial**

    
    
    region = forms.ModelChoiceField(queryset=None,label=u'region')
    
    def __init__(self,*args,**kwargs):
        super(InputForm,self).__init__(*args,**kwargs)
        iquery = Result.objects.values_list('region', flat=True).distinct()
        iquery_choices = [('', '')] + [(region,region)  for region in iquery]
    

I think now it is dic, but it still reports the same error. Please help thanks
in advance.


Answer: You must pass queryset to your
[ModelChoiceField](https://docs.djangoproject.com/en/1.8/ref/forms/fields/#fields-
which-handle-relationships). From docs:

> For more complex uses, you can specify `queryset=None` when declaring the
> form field and then populate the queryset in the form’s `__init__()` method:
    
    
    class inputform(forms.ModelForm):
        region = forms.ModelChoiceField(queryset=None, label=u'Region')
    
    
        def __init__(self,*args,**kwargs):
            super(inputform,self).__init__(*args,**kwargs)
            self.fields['region'].choices=((x['Region'].que,x['Region'].disr) for x in dupont.objects.values('Region').distinct())
    

