Chained dropdown in registration

Hello, i’m new in django and openEdx, i want to create a chained dropdown in register page.
i already followed the tip for Create a Custom Registration Page, but i cant figure out how to make a chained dropdown, is there a way to do this?


Hi! Could you provide an example of the desired behaviour? And some tech context would be cool also (OeX release at least).


for example, i need to make a registration page that i can select State and City, but i need to filter the city options in dropdown based on the state selection. Only cities of selected state must appear in the city’s dropdown
Unfortunetly i can’t upload images =(

i’m running devstack from, i think that is the latest release of open edx, i don’t know, sorry =/


In your form file in CustomForm which should be

what you can do is pass query to chain the form. Something like:

class ExtraInfoForm(forms.ModelForm):
    class Meta:
        model = ExtraInfo
        fields = (''country', 'city')

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['city'].queryset = City.objects.none()

        if 'country' in
                country_id = int('country'))
                self.fields['city'].queryset = City.objects.filter(country_id=country_id).order_by('name')
            except (ValueError, TypeError):
                pass  # invalid input from the client; ignore and fallback to empty City queryset
            self.fields['city'].queryset ='name')

Given that you have data in your form. Have you tried this? I didn’t run the code above but I feel this can work.

Thank you for the response,

I have the data in my City model,

in i have something like

    class ExtraInfo(models.Model):
        state = models.CharField(
        city = models.CharField(

    class City(models.Model):
        name = models.CharField('City', max_length=100, blank=True)
        uf = models.CharField('UF', max_length=2, choices=STATE_CHOICES)

        def __str__(self):

        class Meta:
            ordering = ('name',)
            verbose_name = 'city'
            verbose_name_plural = 'cities'

i wrote the snippet that you sent, but no difference (the good news are that there were no errors), have i to make city in a ForeingKey?

STATE_CHOICES coming from django localflavor

I made city in be ForeignKey and gave the error:

ImproperlyConfigured at /register
Field type 'None' not recognized for registration extension field 'city'.
Request Method:	GET
Request URL:	http://localhost:18000/register
Django Version:	2.2.16
Exception Type:	ImproperlyConfigured
Exception Value:	
Field type 'None' not recognized for registration extension field 'city'.
Exception Location:	/edx/app/edxapp/edx-platform/openedx/core/djangoapps/user_authn/views/ in get_registration_form, line 399
Python Executable:	/edx/app/edxapp/venvs/edxapp/bin/python
Python Version:	3.8.6
Python Path:	
Server time:	Thu, 29 Oct 2020 20:14:38 +0000

Looks like error is because of your form as it is not able to except blank as answers i.e None being set.

city = models.ForeignKey(City, on_delete=models.SET_NULL, null=True)

Perhaps this might help?

i don’t know what i’m doing wrong, but if i declare

city = models.ForeignKey(City, on_delete=models.SET_NULL, null=True)

appers the message undefined name ‘City’ in my IDE, and if a run migrations the same message appers.

is there an way to call City class in

if i wrote

city = models.ForeignKey('City', on_delete=models.SET_NULL, null=True)

the message ‘None’ keeps

i fixed the City and ‘City’ problem.

same error ‘None’ continues

can someone help me? I haven’t yet

forms.ModelChoiceField: "select",
in FIELD_TYPE_MAP in /edx-platform/openedx/core/djangoapps/user_api/ at line 107