Most of the cases where I wanted (or needed) dynamic choices, I've solved 
them by using a normal CharField() on the model and a ChoiceField() in the 
form and enforce the choices there.

Models are persistence layer and the changes here, in my opinion as a first 
time poster in the group, should be tracked through migrations. However, I 
think the option of not doing so under your own responsibility should be 
there. On one hand, you need to enforce a certain range of values from the 
database most of the time and on the other hand, in some cases you need the 
flexibility to add or remove dynamically without sending DDL to the 
database.

On Friday, January 12, 2018 at 4:55:50 AM UTC+4, Josh Smeaton wrote:
>
> https://code.djangoproject.com/ticket/22837 was closed as invalid. It 
> concerns itself with migrations being detected when model field choices 
> (which may be dynamic) change. The workaround suggested is to pass a 
> callable to choices with a link to 
> https://code.djangoproject.com/ticket/13181. However, that ticket only 
> concerns itself with FormField.choices accepting a callable.
>
> There are many times where dynamic choices causes unnecessary migrations 
> to be detected, sometimes in external apps:
>
> - pytz gains new timezone codes
> - country codes are added or removed
> - new states are added to an internal library
> - settings determine the set of choices
>
> I would like to reconsider reopening 
> https://code.djangoproject.com/ticket/22837 with the goal of making 
> ModelField.choices accept a callable. There is sufficient frustration 
> within the community to warrant such a change I feel.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/3ae710d4-dfb1-4e59-81c0-86ae271ed087%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to