I don't know if I am trying the impossible but I have HTML select option that comes from Django's forms.Form's queryset, States.objects.all()
.
Model:
class Countries(models.Model):
name = models.CharField(max_length=25)
Model:
class States(models.Model):
country_id = models.ForeignKey('Countries')
name = models.CharField(max_length=25)
Form:
class sign_up_form_school(forms.Form):
states = forms.ModelChoiceField(
queryset = States.objects.all(),
widget=forms.Select(attrs={
'class': states.country_id.name #is this POSSIBLE?
}))
I want each select option value to have different class as I have tried above but it returns error: name 'states' is not defined.