Dynamic choice fields in Django -


referencing django docs on this, have set following:

category_choices = (     ('food', (         ('burger', 'hamburger'),         ('pizza', 'pizza'),         ),     ('drink', (         ('soda', 'soda'),         ('water', 'water'),         ('milk', 'milk'),         ('beer', 'beer'),         ),     ('dessert' , (         ('ic', 'ice cream'),         ('pie', 'pie'),         ('cake', 'cake'),         ), ) 

i understand referencing initial tuple:

choice = models.charfield(max_length=10, choices=category_choices) 

but how limit food? if have 1 choice list user selects food, drink, or dessert, how limit second choice list food item, or drink items, etc? django docs don't cover part. in advance

examining linked documentation yields response:

"but if find hacking choices dynamic, you’re better off using proper database table foreignkey. choices meant static data doesn’t change much, if ever."

the choices field not intended give dynamic behavior, ie display subsets of choices.

my suggestion create model object accommodate food list.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -