S
S
S4dPanda2015-03-03 18:25:37
Django
S4dPanda, 2015-03-03 18:25:37

There is a form with three fields. Is it possible to make the second field a dropdown dependent list of the first one?

There is a form with three fields. Let's call them service, action and input.

class InputsExtendedForm(forms.Form):
  #action = models.ForeignKey(Action)
  service = forms.CharField(max_length=15, widget=forms.Select(choices=SERVICE_CHOICES))
  action_form = forms.CharField(label='Action', max_length=15)
  input_form = forms.CharField(label='Input', max_length=1000)

The strings for service and action are given in the documentation. For service I created a big tuple
SERVICE_CHOICES = (
    ('Apps', 'Apps'),
    ('Auth', 'Auth'),
    ('Book', 'Book'),

But for each setvice item, there are several lines in the action. Is it possible to create an action_form dropdown list that will display rows depending on the value of service?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
zigen, 2015-03-03
@zigen

Redefine the model and make another class action_form. Through a one-to-many(service-action_form) relationship

D
DAlex, 2015-03-05
@DAlex

I solved a similar problem through java script and onChange event. When changing the main select, you need to either do ajax to the server for data for the dependent select, or process a previously saved list of all possible values ​​​​from some variable that is declared when the page is first rendered.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question