title: Django Prepopulate ModelForm with Table Record
body: <p>I am trying to create an Edit for that allows the user to scroll through a table and click a button existing in each row to edit the data within a modal.</p>
  <p>The issue that I am running into is when I try to prepopulate the form with the existing values. How would I convert the EditCommunicationsForm below to display the current values of the row that you selected edit for?</p>
  <p>forms.py</p>
  <pre><code>class CommunicationsForm(forms.ModelForm):
      class Meta:
          model = Communications
          fields = &quot;__all__&quot;
  
          widgets = {
              'project':forms.TextInput(attrs={'class': 'form-control','placeholder':'Enter your Project Name'}),
              'title':forms.TextInput(attrs={'class': 'form-control','placeholder':'Enter a short Title'}),
              'intent':forms.Textarea(attrs={'class': 'form-control','height':'50px','placeholder':'Describe the intent and desired outcome of the communication'}),
              'date':forms.TextInput(attrs={'class': 'form-control','placeholder':'Select a Date'}),
              'channel':forms.Select(attrs={'class': 'form-control'}),
              'content_type':forms.Select(attrs={'class': 'form-control','placeholder':'Select a Content Type'}),
              'audience':forms.TextInput(attrs={'class': 'form-control','placeholder':'Enter the Audience(s)'}),
              'status':forms.Select(attrs={'class': 'form-control','placeholder':'Select the Status'}),
              }
  
  class EditCommunicationsForm(forms.ModelForm):
      class Meta:
          model = Communications
          fields = &quot;__all__&quot;
  
          widgets = {
              'project':forms.TextInput(attrs={'class': 'form-control','initial':'Project 123'}),
              'title':forms.TextInput(attrs={'class': 'form-control','placeholder':'Enter a short Title'}),
              'intent':forms.Textarea(attrs={'class': 'form-control','height':'50px','placeholder':'Describe the intent and desired outcome of the communication'}),
              'date':forms.TextInput(attrs={'class': 'form-control','placeholder':'Select a Date'}),
              'channel':forms.Select(attrs={'class': 'form-control'}),
              'content_type':forms.Select(attrs={'class': 'form-control','placeholder':'Select a Content Type'}),
              'audience':forms.TextInput(attrs={'class': 'form-control','placeholder':'Enter the Audience(s)'}),
              'status':forms.Select(attrs={'class': 'form-control','placeholder':'Select the Status'}),
              }
  </code></pre>
  <p>views.py</p>
  <pre><code>def communications(request):
      comms_list = Communications.objects.order_by('id')
      if request.method == &quot;POST&quot;:
          new_form = CommunicationsForm(request.POST, request.FILES)
          edit_form = EditCommunicationsForm(request.POST, request.FILES)
          if form.is_valid():
              form.save()
              return redirect('http://127.0.0.1:7000/polls/communications/',{&quot;new_form&quot;:new_form,&quot;edit_form&quot;:edit_form,'comms_list':comms_list})
      else:
          comms = Communications.objects.get(id=**ID**)
          new_form = CommunicationsForm()
          edit_form = EditCommunicationsForm(initial={&quot;project&quot;:comms.project })
  
          query = request.GET.get('search')
          if query:
              postresult = Communications.objects.filter(id__contains=query)
              comms_list = postresult
          else:
              comms_list = Communications.objects.order_by('id')
  
          return render(request,'polls/communications.html',{&quot;new_form&quot;:new_form,&quot;edit_form&quot;:edit_form,'comms_list':comms_list})
  </code></pre>
  <p>urls.py</p>
  <pre><code>    path('communications/', views.communications, name='communications'),
  </code></pre>
  <p>communications.html</p>
  <pre><code>    &lt;!--Edit Modal--&gt;
      &lt;div class=&quot;modal fade&quot; id=&quot;edit&quot; tabindex=&quot;-1&quot; role=&quot;dialog&quot; aria-labelledby=&quot;exampleModalLongTitle&quot; aria-hidden=&quot;true&quot;&gt;
          &lt;div class=&quot;modal-dialog&quot; role=&quot;document&quot;&gt;
              &lt;div class=&quot;modal-content&quot;&gt;
                  &lt;div class=&quot;modal-header&quot;&gt;
                      &lt;h5 class=&quot;modal-title&quot; id=&quot;exampleModalLongTitle&quot;&gt;Create User&lt;/h5&gt;
                      &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;modal&quot; aria-label=&quot;Close&quot;&gt;
                          &lt;span aria-hidden=&quot;true&quot;&gt;&amp;times;&lt;/span&gt;
                      &lt;/button&gt;
                  &lt;/div&gt;
                  &lt;div class=&quot;modal-body&quot;&gt;
                      &lt;form method=&quot;POST&quot;&gt;
                          {% csrf_token %}
                          {{edit_form}}
                          &lt;div class=&quot;modal-footer&quot;&gt;
                              &lt;button type=&quot;button&quot; class=&quot;btn btn-secondary&quot; data-dismiss=&quot;modal&quot;&gt;Close&lt;/button&gt;
                              &lt;button type=&quot;submit&quot; value=&quot;update&quot; class=&quot;btn btn-primary&quot;&gt;Save changes&lt;/button&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  <p>Screenshot (I want to click the yellow Edit on the left and have that specific row's data appear in the modal that pops up):
  <a href="https://i.stack.imgur.com/2C38v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2C38v.png" alt="enter image description here" /></a></p>