Or, you could read either this thread or the doc and take advantage of
the django taking care of you.
Quoting the doc: "If the [choice] argument is a callable, it is
evaluated each time the field’s form is initialized."
That's why I suggested to add "lambda: " before the list
comprehension. To turn the value into a callable.

2016-08-03 16:17 GMT+02:00 Tom Christie <christie....@gmail.com>:
> I'd suggest using `country = forms.ChoiceField(choices=[])` in the form
> declaration itself, and having the form `__init__()` method populate the
> *actual* set of choices. That way the allowable set of choices will always
> reflect whats currently in the DB at the point that the view runs.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/288ec271-0118-46f5-93ba-089343e11cf9%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



-- 

Cordialement, Coues Ludovic
+336 148 743 42

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEuG%2BTb%2BL-xHbcf5FjiVSLgBKvrMAkohreO-F1eAhN%2BBGsCExQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to