Я создал класс обновления для операций put и patch и настроил его также в URL-адресах. Но здесь видна только кнопка «положить». Кнопка исправления недоступна.
views.py
from django.shortcuts import render
from rest_framework.views import APIView
from restapp.models import employee
from restapp.serializers import EmployeeSerializer
from rest_framework.response import Response
from rest_framework.generics import UpdateAPIView
class EmployeeUpdateAPIView(UpdateAPIView):
queryset=employee.objects.all()
serializer_class=EmployeeSerializer
lookup_field='id'
urls.py
from django.contrib import admin
from django.urls import path,re_path
from restapp import views
urlpatterns = [
re_path('api/(?P<pk>\d+)/',views.EmployeeUpdateAPIView.as_view())
]
serializers.py
from rest_framework.serializers import ModelSerializer
from restapp.models import employee
class EmployeeSerializer(ModelSerializer):
class Meta:
model=employee
fields='__all__'
models.py
from django.db import models
class employee(models.Model):
eno = models.IntegerField()
ename = models.CharField(max_length=60)
esal = models.FloatField()
eaddr = models.CharField(max_length=100)