0

I'm a new on Django. One question confused me about the drop down list in Django. I'd like to know how to change the content in a page based on the selection in the drop down list in Django.

In Model.py I design the fields as:

STATUS_IN_CHOICE = (
    ('Pending','Pending'),
    ('Passed','Passed'),
    ('Failed','Failed'),
)
Status = models.CharField(max_length=10,choices=STATUS_IN_CHOICE,
                          default='Pending')

The respected result I want is, if I select "Passed" in the drop down list. All the passed cases show in the page. Others are the same.

I have no idea how to code the template and connect with the field now. Cause in my opinion, it's not a forms (post) at all.

Wtower
  • 18,848
  • 11
  • 103
  • 80
Kent
  • 71
  • 1
  • 10
  • Are you looking for a solution that involves back-end processing? Or are you looking for a client-side-only solution (meaning all cases provided to the client-side and the filtering is done there)? – OrenD May 28 '15 at 08:12
  • Only client-side-only, back-end processing I can filter out in view.py based on the drop down value selection – Kent May 28 '15 at 08:47

1 Answers1

1

You have basically two alternatives, and both of involve the use of javascript.

You either:

  • need to preload all content at the initial page render, if the content is small and simple, and then use javascript on the drop-down to display the appropriate parts of it.
  • or to fetch the content with ajax requests depending on the value of the drop-down and render it when it loads.

Neither of the above the use of a model if the drop-down is for display filter only, and no storing is required. You could achieve the same with a simple django form or plain HTML.

Community
  • 1
  • 1
Wtower
  • 18,848
  • 11
  • 103
  • 80