Pass current value(instance) in the udpate form
<p>I have an api for updating the object. But update form shows empty field. How can i show form filled with current value? If i want to show current value filled in just django, i would do formname(instance=object). How can i do similar in DRF when using RetrieveAPIView. </p>

<pre><code>class RestaurantUpdateAPI(RetrieveAPIView):
    queryset = Restaurant.objects.all()
    serializer_class = RestaurantCreateUpdateSerializer

    def perform_update(self, serializer):
        print('serializer',serializer)
        instance = serializer.save()
        # send_email_confirmation(user=self.request.user, modified=instance)
</code></pre>

<p>This code gives me empty form. i want the name field should have name of restaurant, city should have city name and so on.</p>

<p>How can this be done in DRF RetrieveAPIView?</p>

<p><a href="http://i.stack.imgur.com/jTenj.png" rel="nofollow"><img src="http://i.stack.imgur.com/jTenj.png" alt="enter image description here"></a></p>

<p>You api url is ../edit/..., so I think you wanna use this api to edit your restaurant.(btw, REST API should not use "edit" in it, you just use http method to handle this). In your case, if you want use get method and post method at the same time.You should use <a href="http://www.django-rest-framework.org/api-guide/generic-views/#retrieveupdatedestroyapiview" rel="nofollow">RetrieveUpdateDestroyAPIView</a></p>

<blockquote>
  <p>Used for read-write-delete endpoints to represent a single model instance.</p>
  
  <p>Provides get, put, patch and delete method handlers.</p>
  
  <p>Extends: GenericAPIView, RetrieveModelMixin, UpdateModelMixin, DestroyModelMixin</p>
</blockquote>

python django python-3.x django-rest-framework