私は現在このようなモデルを持っています
class Lg(models.Model):
name = models.CharField(max_length = 50,choices = LG_CHOICES,unique = True)
class State(models.Model):
name = models.CharField(max_length = 50,choices = STATE_CHOICES,unique = True)
lg = models.ManyToManyField(Lg,related_name ='State_Lg',blank= True,null = True)
class AddPlaceForm(forms.Form):
house_number = forms.IntegerField()
street_name = forms.CharField()
area = forms.CharField()
city = forms.CharField()
lg = forms.ChoiceField(choices = Lg.objects.none())
def __init__(self,state_id,*args,**kwargs):
super(GenericPropertyForm,self).__init__(self,*args,**kwargs)
self.fields['lg'] = forms.ChoiceField(choices=list(State.objects.get(id = state_id).lg.select_related()))
このようなビューから状態IDをユーザーに渡してもらいたいform = AddPlaceForm(state_id)
誰でもこれを助けることができます