djangosnippets.org: Latest snippets posted by lsbardelhttps://djangosnippets.org/users/lsbardel/2009-10-20T04:36:25.695117-05:00lsbardelA Lazy ChoiceField implementation
2009-10-20T04:36:25.695117-05:00lsbardelhttps://djangosnippets.org/snippets/1767/<p>Sometimes it is useful to have a ChoiceField which calculates its choices at runtime, when a new instance of a form containing it, is generated. And this is what <code>LazyChoiceField</code> does.
The <code>choices</code> argument must be an <em>iterable</em> as for <code>ChoiceField</code>.</p>
<p><strong>Usage example</strong></p>
<pre><code>from django import forms
DynamicApplicationList = …</code></pre>
Freely redistributable