title: Passing a list into MultipleChoiceField form as initial value
body: <p>I've got a field called 'service'. It stores a list of ints that are representative of the services that a company offers (1=accounting, 2=HR, etc.). Once the list is saved to the 'service' field, I want to be able to pass it in as an 'initial' value to the form so that the user can see what options they previously selected.</p>
  
  <p><b>What works:</b></p>
  
  <p>a) User can select services</p>
  
  <p>b) Services are saved to the 'service' field as a list of ints (eg. [2, 3, 5])</p>
  
  <p><b>What doesn't work:</b></p>
  
  <p>a) No initial values are shown within the form despite the fact that 'service' contains a list of ints.</p>
  
  <p>model.py</p>
  
  <pre><code>class BaseServicesOffered(models.Model):
      user = models.OneToOneField(User, on_delete=models.CASCADE)    
      service = models.CharField(max_length=255, default='', null=True, blank=True)
  
      def __str__(self):
          return self.user.username                                          
  </code></pre>
  
  <p>form.py</p>
  
  <pre><code>class BaseServicesOfferedForm(forms.ModelForm):
      service = forms.MultipleChoiceField(required=False, widget=forms.CheckboxSelectMultiple)
  
      def __init__(self, *args, **kwargs):
          user = kwargs.pop('user')  
          selectedservices = kwargs.pop('selectedservices')
          super(BaseServicesOfferedForm, self).__init__(*args, **kwargs)
          self.fields['service'].choices = [(t.id, t.service) for t in AllServices.objects.filter(industrycode=user.userprofile.industry)]
          self.fields['service'].initial = selectedservices
  
      class Meta:  
          exclude = ('user',)
          model = BaseServicesOffered
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>@login_required(login_url="/accounts/login/")    
  def baseservicesoffered(request):
  
      try:
          base_services_offered = BaseServicesOffered.objects.create(user=request.user)
  
      except:
          pass
  
      user = request.user
      services = user.baseservicesoffered.service
      instance = get_object_or_404(BaseServicesOffered, user=user)
      form = BaseServicesOfferedForm(request.POST or None, user=request.user, selectedservices=services, instance=instance)    
  
      if request.method == 'POST':
  
          if form.is_valid():
              instance = form.save(commit=False)
              instance.user = request.user
  
              service = form.cleaned_data['service']
              services = [int(i) for i in service] 
              instance.service = services
  
              instance.save()
              return redirect('/accounts/profile/')
  
          else:
              context = {'form': form}
              return render(request, 'accounts/setup8.html', context)
  
      context = {'form': form}            
      return render(request, 'accounts/setup8.html', context)
  </code></pre>
  
  <p>Thanks for the help!</p>