Sometimes we may need to generate a *ModelChoiceField* in which choices are generated at runtime, depending on the locale language. The snippet generates a *ChoiceField* based on a queryset and a specific attribute of the Model, ordering the choices by the attribute content in the locale language.
**Usage example** (inside a form declaration)
country = LazyModelChoiceField(sort_by='name', queryset = \
Country.objects.all, empty_label=_('All countries'), label=_('Country'))
Based on lsbardel LazyChoiceField implementation (snippet 1767)
- forms
- model
- field
- ModelChoiceField