- 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
- Treat empty value on DateRangeFilter as a filter for non filled dates by kmmbvnr 1 month, 1 week ago
- Django Settings Assignment Expressions aka Walrus Operator example by webology 2 months, 1 week ago
- codigo alto nivel by MrRocklion 4 months ago
- Load template from specific app by Krzysiek555 4 months, 3 weeks ago
- PostgreSQL JSON subqueries by dolamroth 4 months, 3 weeks ago