PUT or PUSH for modifying the existing data?
Question:
I have viewset,
class CompanyViewSet(viewsets.ModelViewSet):
serializer_class = s.CompanySerializer
queryset = m.Company.objects.all()
Which shows the view on /api/companys
There is a button for POST
I can add the new data from this form.
Now I want to modify the existing data.
I have basic questions.
-
PUSH
can modify the data? or PUT
should be implemented?
-
How PUT
can be implemented for ModelViewSet
?
Answers:
Mainly for updating(modify) data using PATCH
method, PUT
for replace data
Description of methods:
https://www.restapitutorial.com/lessons/httpmethods.html
To define PUT method you can use follow example:
# define url
urlpatterns = [
url('api/mydata/<id>', views.data_put),
]
# views
@api_view(['PUT'])
def data_put(r, d):
I have viewset,
class CompanyViewSet(viewsets.ModelViewSet):
serializer_class = s.CompanySerializer
queryset = m.Company.objects.all()
Which shows the view on /api/companys
There is a button for POST
I can add the new data from this form.
Now I want to modify the existing data.
I have basic questions.
-
PUSH
can modify the data? orPUT
should be implemented? -
How
PUT
can be implemented forModelViewSet
?
Mainly for updating(modify) data using PATCH
method, PUT
for replace data
Description of methods:
https://www.restapitutorial.com/lessons/httpmethods.html
To define PUT method you can use follow example:
# define url
urlpatterns = [
url('api/mydata/<id>', views.data_put),
]
# views
@api_view(['PUT'])
def data_put(r, d):