i'm working in OpenEdx and i'm trying to make a registration page that contains custom fields, state and city.
here is my models.py:
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):
return self.name
class Meta:
ordering = ('name',)
verbose_name = 'cidade'
verbose_name_plural = 'cidades'
class UserProfileExtras(models.Model):
user = models.OneToOneField(
USER_MODEL,
null=True,
on_delete=models.CASCADE
)
state = models.CharField(
verbose_name="State",
choices=STATE_CHOICES,
max_length=100,
)
city = models.CharField(
verbose_name="Cidade",
max_length=100,
null=True,
)
and forms.py:
class UserProfileExtrasForm(ModelForm):
class Meta(object):
model = UserProfileExtras
fields = ('state', 'city')
def __init__(self, *args, **kwargs):
super(UserProfileExtrasForm, self).__init__(*args, **kwargs)
self.fields['state'].label = _(u"Estado")
self.fields['state'].error_messages = {
"required": _(u"Selecione seu Estado."),
"invalid": _(u"Estado inválido."),
}
self.fields['city'].label = _(u"Cidade")
self.fields['city'].error_messages = {
"required": _(u"Selecione sua cidade."),
"invalid": _(u"Cidade inválida"),
}
i want to make the city dropdown appears only the selected state's cities
thanks