title: Django - Dynamic ChoiceField - All images in static dir
body: <p>I would like to create an app that will allow the user to choose an image between all those contained into a specific folder. The dropdown input would render a thumbnail of the image and the filename. <strong>The choice value would be the path of the image.</strong></p>
  
  <p>I know it could be possible to do it with <a href="http://www.marghoobsuleman.com/jquery-image-dropdown" rel="nofollow noreferrer">jQuery UI and javascript</a>, but I would like to know how I could generate the choices dynamically in the form in order to get the visual effect needed.</p>
  
  <p>If you have other ideas, thank you for any suggestion</p>
  
  <p>dynamic form (not complete):</p>
  
  <pre><code>filename_list = ???
  path_list = ???
  images_thumbnails_list = ???
  
  class imagesForm(forms.Form):
      def __init__(self, user, *args, **kwargs):
          super(imagesForm, self).__init__(*args, **kwargs)
          self.fields['selectedImage'] = forms.ChoiceField(choices=
                           for path in path_list: str(path),
                           for filename in filename_list: str(filename)
                           for thumbnail in images_thumbnails_list: thumbnail )
  </code></pre>
  
  <p>example of input field needed:</p>
  
  <pre><code>  &lt;select name="webmenu" id="webmenu"&gt;
      &lt;option value="calendar" data-image="icons/icon_calendar.gif"&gt;Calendar&lt;/option&gt;
      &lt;option value="shopping_cart" data-image="icons/icon_cart.gif"&gt;Shopping Cart&lt;/option&gt;
      &lt;option value="cd" data-image="icons/icon_cd.gif"&gt;CD&lt;/option&gt;
      &lt;option value="email"  selected="selected" title="icons/icon_email.gif"&gt;Email&lt;/option&gt;
      &lt;option value="faq" data-image="icons/icon_faq.gif"&gt;FAQ&lt;/option&gt;
      &lt;option value="games" data-image="icons/icon_games.gif"&gt;Games&lt;/option&gt;
    &lt;/select&gt;
  </code></pre>
  
  <p>visual example:</p>
  
  <p><img src="https://i.stack.imgur.com/ezLUF.png" alt="enter image description here"></p>