title: using a queryset to generate options for select widget on IntegerField in Django
body: <p>I'm trying to make a site where users can have multiple avatars and pick the one they want to use when entering a room.  (It will be a dice-rolling app.)  I've been stuck for three days trying to figure out how to pass a queryset into a form to use as the options for a select widget that's on an IntegerField.  Right now, I think I have successfully passed the information into the form, but nothing is rendering in the widget.  (I've even got a print statement in the form to prove to myself that the information has made its way in.)</p>
  
  <p>model.py</p>
  
  <pre><code>class EnterSWroom(models.Model):
      room_number = models.IntegerField(blank=False)
      passcode = models.CharField(max_length=100, blank=True, null=True)
      default_avatar = models.IntegerField(default=0)
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>class Enter_SW_Room(forms.ModelForm):
      class Meta:
          model = EnterSWroom
          widgets = {'default_avatar': forms.Select(choices=[])}
          fields = ('room_number', 'passcode', 'default_avatar')
  
      def __init__(self, *args, **kwargs):
          imported_list = kwargs.pop('avatar_list')
          super().__init__(*args, **kwargs)
          self.fields['default_avatar'].choices = imported_list
          print(self.fields['default_avatar'].choices)  #this is just for debugging; see example below
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>class DockingBay(FormMixin, TemplateView):
      form_class = Enter_SW_Room
  
      def get_form_kwargs(self):
          kwargs = super().get_form_kwargs()
          # get tuples for avatar choices
          # get user first name (if exists), else use username
          if self.request.user.userprofile.user_first_name:
              user_name = self.request.user.userprofile.user_first_name
          else:
              user_name = self.request.user.username
          # instantiate avatars list, start with user name
          my_avatars = Avatar.objects.filter(user_id=self.request.user.id)
          my_avatars_choices = [(0, user_name)]
          for avatar in my_avatars:
              if avatar.deleted != 1:
                  my_avatars_choices.append((avatar.id, avatar.avatar_name))
          kwargs['avatar_list'] = my_avatars_choices
          return kwargs
  
      def get(self, request, *args, **kwargs):
          kwargs = self.get_form_kwargs()
          # cut for brevity
          form = Enter_SW_Room(**kwargs)
          args = {'form': form, # other args that were cut from this example}
  
          return render(request, self.template_name, args)
  ...
  </code></pre>
  
  <p>Example of a print: <code>[(0, 'Eric')]</code>
  But, even though the print suggests that I've successfully gotten the queryset to the form, the selection widget displays nothing.</p>
  
  <p>Thanks in advance!</p>
  
  <p>edit to add snippet of html template:</p>
  
  <pre><code>&lt;form method="post"&gt;
      {% csrf_token %}
      &lt;table&gt;
          &lt;col width="240"&gt;
          &lt;col width="120"&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Room ID:&lt;/strong&gt;
              &lt;br&gt;This will be a number.&lt;/td&gt;
              &lt;td&gt;{{form.room_number}} &lt;br&gt;
                  &lt;strong&gt;{{ form.room_number.errors }}&lt;/strong&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Passcode:&lt;/strong&gt;
              &lt;br&gt;If the room is open, or you've been in it before, leave this  blank.&lt;/td&gt;
              &lt;td&gt;{{form.passcode}} &lt;br&gt;
                  &lt;strong&gt;{{ form.passcode.errors }}&lt;/strong&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Avatar:&lt;/strong&gt;
              &lt;br&gt;Select your avatar.&lt;/td&gt;
              &lt;td&gt;{{form.default_avatar}} &lt;br&gt;
                  &lt;strong&gt;{{ form.default_avatar.errors }}&lt;/strong&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;button type="submit"&gt;Enter Room&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>