title: UpdateView in Django shows blank forms instead of Database previous data
body: <p>I'm using UpdateView to edit data using forms.</p>
  
  <p>After I click to edit the <code>popup</code> using modal is showing the forms with blank data! It doesn't retrieve the previous data that was in the Database.
  Anyone know what should I add?</p>
  
  <p>I am stuck with this edit for about a week :(</p>
  
  <p>If anyone has a clue I will be grateful! 
  Thank you!</p>
  
  <p>view.py-</p>
  
  <pre><code>from django.shortcuts import render_to_response
  from django.shortcuts import get_object_or_404
  from django.shortcuts import render, redirect
  from django.template import RequestContext
  from django.views.generic import TemplateView, UpdateView, DeleteView, CreateView
  from DevOpsWeb.forms import HomeForm
  from DevOpsWeb.models import serverlist
  from django.core.urlresolvers import reverse_lazy
  from simple_search import search_filter
  from django.db.models import Q
  class HomeView(TemplateView):
  
  template_name = 'serverlist.html'
  
  
  def get(self, request):
      form = HomeForm()
      query = request.GET.get("q")
      posts = serverlist.objects.all()
  
      if query:
          posts = serverlist.objects.filter(Q(ServerName__icontains=query) | Q(Owner__icontains=query) | Q(Project__icontains=query) | Q(Description__icontains=query) | Q(IP__icontains=query) | Q(ILO__icontains=query) | Q(Rack__icontains=query))
      else:
          posts = serverlist.objects.all()
      args = {'form' : form, 'posts' : posts}
      return render(request, self.template_name, args)
  
  def post(self,request):
      form = HomeForm(request.POST)
      posts = serverlist.objects.all()
  
  
  
      if form.is_valid(): # Checks if validation of the forms passed
          post = form.save(commit=False)
          #if not form.cleaned_data['ServerName']:
          #post.servername = " "
          post.save()
          #text = form.cleaned_data['ServerName']
          form = HomeForm()
          return redirect('serverlist')
  args = {'form': form,  'text' : text}
  return render(request, self.template_name,args)
  
  
  class PostDelete(DeleteView):
      model = serverlist
      success_url = reverse_lazy('serverlist')
  
  class PostEdit(UpdateView):
      model = serverlist
      #post = serverlist.objetcs.get(server_id=server_id)
      fields = ['ServerName','Owner','Project','Description','IP','ILO','Rack','Status']
      success_url=reverse_lazy('serverlist')
  </code></pre>
  
  <p>urls.py -</p>
  
  <pre><code>from django.conf.urls import url, include
  from DevOpsWeb.views import HomeView
  from DevOpsWeb.views import PostDelete
  from DevOpsWeb.views import PostEdit
  from django.contrib import admin
  admin.autodiscover()
  
  urlpatterns = [
      # Examples:
      url(r'^$', HomeView.as_view(), name='serverlist'),
  
       url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
       #DevOpsWeb:8000/Delete/
       url(r'^delete/(?P&lt;pk&gt;\d+)/$', PostDelete.as_view(), name="delete_post"),
       url(r'^django_popup_view_field/', include('django_popup_view_field.urls', namespace="django_popup_view_field")),
       url(r'^admin/', include(admin.site.urls)),
       #DevOpsWeb:8000/edit/
       url(r'^edit/(?P&lt;pk&gt;\d+)/$', PostEdit.as_view(), name="edit_post"),
  ]
  </code></pre>
  
  <p>forms.py -</p>
  
  <pre><code>from django import forms
  from DevOpsWeb.models import serverlist
  
  
  class HomeForm(forms.ModelForm):
      ServerName = forms.CharField(widget=forms.TextInput,max_length = 30,required=False)
      Owner = forms.CharField(max_length = 50,required=False)
      Project = forms.CharField(max_length = 30,required=False)
      Description = forms.CharField(max_length = 255,required=False)
      IP = forms.CharField(max_length = 30,required=False)
      ILO = forms.CharField(max_length = 30,required=False)
      Rack = forms.CharField(max_length = 30,required=False)
      Status = forms.CharField(max_length = 30,required=False)
      class Meta:
          model = serverlist
          fields = ('ServerName' ,'Owner','Project','Description','IP','ILO','Rack','Status',)
  
  class AutoCompleteModelChoiceField(forms.ModelChoiceField):
      widget = forms.TextInput
  def clean(self, value):
      value = super(AutoCompleteModelChoiceField, self).clean(value)
      return value
  
  
  class serverForm(forms.ModelForm):
      hotel = AutoCompleteModelChoiceField(queryset=serverlist.objects.all())
  </code></pre>
  
  <p>index.html (The part with the edit button)-</p>
  
  <pre><code>            &lt;div class="modal fade bd-example-modal-sm" id="Edit{{server.id}}" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true"&gt;
    &lt;div class="modal-dialog modal-sm"&gt;
      &lt;div class="modal-content"&gt;
                          &lt;div class="modal-header"&gt;
                                  &lt;h5 class="modal-title"&gt;Edit Server &lt;b&gt;{{ server.ServerName }}&lt;/b&gt; &lt;/h5&gt;
                                  &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;
                                          &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
                                  &lt;/button&gt;
                          &lt;/div&gt;
                                  &lt;div class="modal-body"&gt;
                                          &lt;form action="{% url 'edit_post' server.id %}" method="post"&gt; {% csrf_token %}
                                  &lt;!--&lt;center&gt;    {{ form.as_p }} &lt;/center&gt; --&gt;
                                                          {% for field in form %}
                                                                  &lt;div class="fieldWrapper"&gt;
                                                  {{ field.errors }}
                                                                          &lt;!-- {{ field.label_tag }} --&gt;
  
                                  &lt;small&gt;&lt;b&gt;{{ field.html_name }}&lt;p align="left"&gt;&lt;/b&gt; {{ field }}&lt;/small&gt; &lt;/p&gt;
  
                                                  {% if field.help_text %}
                                                  &lt;p class="help"&gt;{{ field.help_text|safe }}&lt;/p&gt;
                                                  {% endif %}
  
                                                          &lt;/div&gt;
  
  
                                  {% endfor %}
                  &lt;/div&gt;
                  &lt;div class="wrapper"&gt;
                  &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp
                  &lt;h2&gt;&lt;button type="submit" class="save btn btn-success btn-lg"&gt;Confirm&lt;/button&gt;&lt;/h2&gt;&amp;nbsp&amp;nbsp&amp;nbsp
                                  &lt;h2&gt;&lt;button type="submit" class="btn btn-secondary btn-lg" data-dismiss="modal"&gt;Cancel&lt;/button&gt;&lt;/h2&gt;
                  &lt;/div&gt;
                  &lt;/form&gt;
              &lt;/td&gt;
                  &lt;/div&gt;
          &lt;/tr&gt;
                  {% endfor %}
  </code></pre>
  
  <p>The posts and the edit button:</p>
  
  <pre><code>                {% for server in posts %}
  
          &lt;tr&gt;
            &lt;div class ="server"&gt;
              &lt;td&gt;&lt;/td&gt;
              &lt;td&gt;&lt;center&gt;{{ server.ServerName }}&lt;/center&gt;&lt;/td&gt;
              &lt;td&gt;&lt;center&gt;{{ server.Owner }}&lt;/center&gt;&lt;/td&gt;
              &lt;td&gt;&lt;center&gt;{{ server.Project }}&lt;/center&gt;&lt;/td&gt;
              &lt;td&gt;&lt;center&gt;{{ server.Description }}&lt;/center&gt;&lt;/td&gt;
              &lt;td&gt;&lt;center&gt;{{ server.IP }}&lt;/center&gt;&lt;/td&gt;
              &lt;td&gt;&lt;center&gt;{{ server.ILO }}&lt;/center&gt;&lt;/td&gt;
              &lt;td&gt;&lt;center&gt;{{ server.Rack }}&lt;/center&gt;&lt;/td&gt;
              &lt;td&gt;&lt;h4&gt;&lt;span class="badge badge-success"&gt;{{ server.Status }}&lt;/span&gt;&lt;/h4&gt;&lt;/td&gt;&lt;/center&gt;
  
              &lt;td&gt;
  
  &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp
              &lt;button type="button" class="btn btn-outline-danger" data-toggle="modal" href="#delete-server-{{server.id}}"
               data-target="#Del{{server.id}}"&gt;Delete &lt;i class="fa fa-trash-o"&gt;&lt;/i&gt;&lt;/button&gt;&amp;nbsp
              &lt;button type="button" class="btn btn-outline-primary" data-toggle="modal" href="#edit-server-{{server.id}}"
               data-target="#Edit{{server.id}}"&gt; &amp;nbsp&amp;nbspEdit&amp;nbsp           &lt;i class="fa fa-pencil"&gt;&lt;/i&gt;&lt;/button&gt;
  &amp;nbsp
  
  
                          &lt;div id ="Del{{server.id}}" class="modal fade" role="document"&gt;
                              &lt;div class="modal-dialog" id="delete-server-{{server.id}}"&gt;
                                      &lt;div class="modal-content"&gt;
                                          &lt;div class="modal-header"&gt;
                                              &lt;h5 class="modal-title"&gt;Delete Confirmation&lt;/h5&gt;
                                              &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;
                                  &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
                                      &lt;/button&gt;
                                          &lt;/div&gt;
                                          &lt;div class="modal-body"&gt;
                                          &lt;form action="{% url 'delete_post' server.id %}" method="post"&gt;{% csrf_token %}
                                              &lt;h6&gt;Are you sure you want to delete {{ server.ServerName }}?&lt;/h6&gt;
                                                  &lt;br&gt;
                                              &lt;center&gt;&lt;input type="submit" class="btn btn-danger btn-md" value="Confirm"/&gt;
                                                  &lt;button type="submit" class="btn btn-secondary" data-dismiss="modal"&gt;Cancel&lt;/button&gt;&lt;/center&gt;
  
                                          &lt;/form&gt;
                                      &lt;/div&gt;
                                      &lt;/div&gt;
  
  
                          &lt;/div&gt;
              &lt;/div&gt;
  
  
  
  
              &lt;div class="modal fade bd-example-modal-sm" id="Edit{{server.id}}" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true"&gt;
    &lt;div class="modal-dialog modal-sm"&gt;
      &lt;div class="modal-content"&gt;
                          &lt;div class="modal-header"&gt;
                                  &lt;h5 class="modal-title"&gt;Edit Server &lt;b&gt;{{ server.ServerName }}&lt;/b&gt; &lt;/h5&gt;
                                  &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;
                                          &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
                                  &lt;/button&gt;
                          &lt;/div&gt;
                                  &lt;div class="modal-body"&gt;
                                          &lt;form action="{% url 'edit_post' server.id %}" method="post"&gt; {% csrf_token %}
                                  &lt;!--&lt;center&gt;    {{ form.as_p }} &lt;/center&gt; --&gt;
                                                          {% for field in form %}
                                                                  &lt;div class="fieldWrapper"&gt;
                                                  {{ field.errors }}
                                                                          &lt;!-- {{ field.label_tag }} --&gt;
  
                                  &lt;small&gt;&lt;b&gt;{{ field.html_name }}&lt;p align="left"&gt;&lt;/b&gt; {{ field }}&lt;/small&gt; &lt;/p&gt;
  
                                                  {% if field.help_text %}
                                                  &lt;p class="help"&gt;{{ field.help_text|safe }}&lt;/p&gt;
                                                  {% endif %}
  
                                                          &lt;/div&gt;
  
  
                                  {% endfor %}
                  &lt;/div&gt;
                  &lt;div class="wrapper"&gt;
                  &amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp&amp;nbsp
                  &lt;h2&gt;&lt;button type="submit" class="save btn btn-success btn-lg"&gt;Confirm&lt;/button&gt;&lt;/h2&gt;&amp;nbsp&amp;nbsp&amp;nbsp
                                  &lt;h2&gt;&lt;button type="submit" class="btn btn-secondary btn-lg" data-dismiss="modal"&gt;Cancel&lt;/button&gt;&lt;/h2&gt;
                  &lt;/div&gt;
                  &lt;/form&gt;
              &lt;/td&gt;
                  &lt;/div&gt;
          &lt;/tr&gt;
                  {% endfor %}
      &lt;/tbody&gt;
  &lt;/h5&gt;
      &lt;/table&gt;
  </code></pre>