[Fixed]-Django: Use post() in UpdateView to populate form's fields with instance's existing field values

1👍

Look to the UpdateView docs

This View has method get_object(self, queryset=None)

In you case just need to call it in POST method something like this:

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)

Leave a comment