- February 26, 2007
- Pre .96
- 13 (after 13 ratings)
This is an excerpt from the form code used on this site; the tricky bit here is making the
choices for the
language field get filled in dynamically from
Language.objects.all() on each form instantiation, so that new languages can be picked up automatically. It also adds a blank choice at the beginning so that users can't accidentally ignore the field and incorrectly end up with whatever Language was first in the list.
If you use this, always remember that you have to call the superclass
__init__ before you set your dynamic choices, and that you need to accept
**kwargs so you can pass them to it.
ModelChoiceField will solve this, but it still seems to be a bit buggy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
More like this
- Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 2 months, 3 weeks ago
- Python Django CRUD Example Tutorial by tuts_station 3 months, 1 week ago
- Browser-native date input field by kytta 4 months, 3 weeks ago
- Generate and render HTML Table by LLyaudet 5 months ago
- My firs Snippets by GutemaG 5 months, 1 week ago