Django: Use post() in UpdateView to populate form's fields with instance's existing field values
<p>I have trouble getting the current instance's fields on my UpdateView. How do I get the specific instance based on its id?</p>

<p><strong>views.py</strong></p>

<pre><code>class ShowUpdate(UpdateView):
  model = Show
  fields = ['description', 'season', 'episode']

  def post(self, request, **kwargs):
      request.POST = request.POST.copy()
      request.POST['description'] = "how to get instance description?" # problem here
      request.POST['season'] = 2
      return super(ShowUpdate, self).post(request, **kwargs)
</code></pre>

<p><strong>models.py</strong></p>

<pre><code>class Show(models.Model):
  owner = models.ForeignKey(User, null=True, default=True, related_name='o')
  title = models.CharField(max_length=100)
  description = models.TextField(default='N/A', blank=True, max_length=250)
  season = models.IntegerField(default=0)
  episode = models.IntegerField(default=0)

  def get_absolute_url(self):
      return reverse('show:index')

  def __str__(self):
      return self.title
</code></pre>

<p>Look to the <a href="http://ccbv.co.uk/projects/Django/1.10/django.views.generic.edit/UpdateView/" rel="nofollow">UpdateView</a> docs</p>

<p>This View has method <code>get_object(self, queryset=None)</code></p>

<p>In you case just need to call it in <code>POST</code> method something like this:</p>

<pre><code>class ShowUpdate(UpdateView):
  model = Show
  fields = ['description', 'season', 'episode']

  def post(self, request, **kwargs):
      self.object = self.get_object()
      request.POST = request.POST.copy()
      request.POST['description'] = self.object.description
      request.POST['season'] = 2
      return super(ShowUpdate, self).post(request, **kwargs)
</code></pre>

python django