0

I was wondering if it was possible to build two dropdown menus where the second has options dependent on what is selected in the first one? I have three classes, in the field 'step' in RouteStep is a series of processes, for example Heat Treatment and Removal. I'd like if one of these processes is selected, only fields from 'step_option' associated with that process shows up, similar to a dropdown where selecting a car manufacturer and only getting their models. Is this possible in django forms?

class Step(models.Model):
    name = models.CharField(_('Step Name'), max_length=100, default='')
    def __unicode__ (self):
            return self.name

class StepOption(models.Model):
    step = models.ForeignKey(Step, related_name = 'Step', null = True)
    name = models.CharField(_('Step Option'), max_length=100, default='')
    def __unicode__ (self):
            return self.name + " - " + self.step.name

class RouteStep(models.Model):
    step_number = models.PositiveIntegerField(_('Step Number'), default = 0)
    step =  models.ForeignKey(Step, related_name = 'Step+', null = True)    
    step_option = models.ForeignKey(StepOption, related_name = 'StepOption', null=True)
    def __unicode__ (self):
            return self.step_option
Ahmad Sidawi
  • 45
  • 1
  • 1
  • 7

1 Answers1

0

I don't want to give you the answer becuase you will never learn that way. Look at this link:

If that doesn't work out look at this one... It was never answered by the person that asked the question resolved it themselves on Github:

Community
  • 1
  • 1