Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Handling HTML <Select> in Django/Python

 
Jarrad Lewis
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to build a checkbox table in a web app to select a list of Students to assign an activity date to. I'm not sure how to get Python or Django to detect the selected students within views.py to perform the function.

Any help gratefully appreciated from a balding newbie.
 
Tim Holloway
Saloon Keeper
Posts: 22259
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Jarrad!

I haven't worked with Django in a long time, but I can at least set you straight on the HTML.

HTML <SELECT> is a tag that's used to indicate a selection list. It's parent to <OPTION> tags that list possible selections, and when the form that contains them is submitted, it will include the name of the SELECT tag and the value of the selected OPTION.

Checkboxes are a different type of tag entirely. Each checkbox is independent and can only return a binary value. Actually, in HTML, submitting a form with checkboxes sends only the names of the checkboxes whose value are true (checked). Unchecked box names don't get sent.

At this point Django takes over and I'm pretty sure that it's providing the Controller component of a Model/View/Controller scheme. Specifically, it populates backing values based on the submitted form. Meaning that if you have a set of boolean variables mapped to checkboxes on the form, an incoming request will have updated those values automatically. Because that's what Controllers do. So you design your form, map form controls to backing value variables, and when you get an incoming request, the data should have already been set and waiting for you. If you want simply to count the number of boxes checked, you'd enumerate the boolean variables corresponding to those check boxes and count the number of them that were set to True.
 
Can you hear that? That's my theme music. I don't know where it comes from. Check under this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic