title: Having an edit form and a detail view on the same page
body: <p>I am currently trying to get an edit form working on the same page as a detail view in <code>Django</code>.</p>
  
  <p>I am currently trying out the way as recommended on the docs (i.e. using <code>FormMixin</code>). So, my view looks like this:</p>
  
  <pre><code>class ProductiveMinutesDetail(FormMixin, DetailView):
      model = models.ProductiveMinutes
      pk_url_kwarg = 'productiveminutes_pk'
      form_class = forms.EditForm
  
      def get_success_url(self):
          return reverse_lazy('productiveminutes_list')
  
      def get_context_data(self, **kwargs):
          context = super(ProductiveMinutesDetail, self).get_context_data(**kwargs)
          context['form'] = forms.EditForm(initial={'post': self.object})
          return context
  
      def post(self, request, *args, **kwargs):
          self.object = self.get_object()
          form = self.get_form()
          if form.is_valid():
              return self.form_valid(form)
          else:
              return self.form_invalid(form)
  
      def form_valid(self, form):
          form.save()
          return super(ProductiveMinutesDetail, self).form_valid(form)
  </code></pre>
  
  <p>And my form looks like this:</p>
  
  <pre><code>from django import forms
  from . import models
  
  class EditForm(forms.ModelForm):
      class Meta:
          model = models.ProductiveMinutes
          fields = ('name', 'description',)
  </code></pre>
  
  <p>The model I am using is this:</p>
  
  <pre><code>class Scenario(models.Model):
      name = models.CharField(max_length=200)
  
  class ProductiveMinutes(models.Model):
      scenario = models.OneToOneField(Scenario)
      name = models.CharField(max_length=200)
      amount = models.DecimalField(max_digits=50, decimal_places=2)
      description = models.CharField(max_length=200)
  </code></pre>
  
  <p>Using this I can get the form to render on the page but I know I am doing something wrong as the fields are empty when I would like them to be populated with the data that is already present.</p>
  
  <p>Another piece of complexity is that this form should not be editing the <code>amount</code> field of the model just the <code>name</code> and <code>description</code>. The <code>amount</code> value is edited separately from the detail view of this page.</p>
  
  <p>So, I guess my main question is how can I get the form to be populated with the data for the models fields that is already present and then edit it. Ideally functionality like that of the generic <code>UpdateView</code> that Django provides.</p>
  
  <p>I am using Django version 1.10</p>
  
  <p>Any help with this would be much appreciated</p>
  
  <p>Thanks for your time</p>
  
  <p>UPDATE:</p>
  
  <p>My template looks like this:</p>
  
  <pre><code>{% extends 'pages/dashboard.html' %}
  {% load i18n humanize crispy_forms_tags %}
  
  {% block content %}
      &lt;div&gt;
          &lt;h1 class="text-center"&gt;Productive Minutes: {{ productiveminutes.name }}&lt;/h1&gt;
          &lt;div class="row"&gt;
              &lt;div class="col"&gt;&lt;/div&gt;
              &lt;div class="col-md-8 col-lg-8"&gt;
                  &lt;h3&gt;Edit productive minutes: {{ productiveminutes.name }}&lt;/h3&gt;
                  &lt;form role="form" method="post"&gt;
                      {% csrf_token %}
                      {{ form|crispy }}
                      &lt;button class="primaryAction btn btn-primary pull-right" type="submit"&gt;{% trans "Submit" %}&lt;/button&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
              &lt;div class="col"&gt;&lt;/div&gt;
          &lt;/div&gt;
          &lt;hr&gt;
          &lt;div class="row"&gt;
              &lt;div class="col"&gt;&lt;/div&gt;
              &lt;div class="col-md-8 col-lg-8"&gt;
                  &lt;h3&gt;Data Records&lt;/h3&gt;
                  &lt;div class="table-responsive"&gt;
                      &lt;table class="table table-bordered"&gt;
                          &lt;thead class="thead-default"&gt;
                              &lt;tr&gt;
                                  &lt;th&gt;ID&lt;/th&gt;
                                  &lt;th&gt;Productive Minutes&lt;/th&gt;
                                  &lt;th&gt;Action&lt;/th&gt;
                              &lt;/tr&gt;
                          &lt;/thead&gt;
                          &lt;tbody&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;{{ productiveminutes.id }}&lt;/td&gt;
                                  &lt;td&gt;{{ productiveminutes.amount|intcomma }}&lt;/td&gt;
                                  &lt;td&gt;
                                      &lt;a href="#"&gt;&lt;i class="fa fa-pencil"&gt;&lt;/i&gt;&lt;/a&gt;
                                      &lt;a href="#"&gt;&lt;i class="fa fa-trash"&gt;&lt;/i&gt;&lt;/a&gt;
                                  &lt;/td&gt;
                              &lt;/tr&gt;
                          &lt;/tbody&gt;
                      &lt;/table&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="col"&gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  {% endblock content %}
  </code></pre>