Django rest framework doesn't display all fields and doesn't apply pagination


I don’t have any idea what is causing this problem. Django rest framework doesn’t display all fields when I want to post data, it also doesn’t apply pagination. Here is code:

class BookApiList(APIView):
    def get(self, request, format = None):
        books = Book.objects.all()

        serializer = BookSerializer(books, many = True)
        return Response(
    def post(self, request, format = None):

        serializer = BookSerializer(data =
        if serializer.is_valid():
            return Response(, status = status.HTTP_201_CREATED)
        return Response(serializer.errors, status = status.HTTP_400_BAD_REQUEST)

class BookApiDetail(APIView):
    def get_object(self, name):
            book = Book.objects.get(title = name)
            return book
            raise Http404

    def get(self, request, name, format = None):
        book = self.get_object(name)
        serializer = BookSerializer(book)
        return Response(
    def put(self, request, name, format = None):
        book = self.get_object(name)
        serializer = BookSerializer(book, data =
        if serializer.is_valid():
            return Response(
        return Response(serializer.errors, status = status.HTTP_400_BAD_REQUEST)

    def delete(self, request, name, format=None):
        book = self.get_object(name)
        return Response(status = status.HTTP_204_NO_CONTENT)

class Book(models.Model):
    user = models.ForeignKey(User, on_delete = models.CASCADE, null = True, blank = True)
    image = models.ImageField(default = "Nana.jpg", upload_to = 'images/', null = True, blank = True)
    title = models.CharField(max_length = 150, unique = True)
    author = models.CharField(max_length = 100)
    category = models.CharField(max_length = 100)
    description = models.TextField(max_length = 5000, null = True, blank = True)
    published_date = models.DateField(null = True, blank = True)
    language = models.CharField(max_length = 100, null = True, blank = True, default = "Not selected")
    read_book_count = models.IntegerField(default = 0)

    def __str__(self):
        return self.title

class BookSerializer(serializers.ModelSerializer):

    class Meta:
        model = Book
        fields = [ 'title', 'author', 'category', 'description', 'published_date', 'language']

path('library/api/books/', views.BookApiList.as_view(), name = 'api_list'),
path('library/api/books/<slug:name>/', views.BookApiDetail.as_view(), name = 'book_api_detail'),

    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 1

When I go to first url link I get all data and this form:
enter image description here

But it should give me a form with all my fields. Thanks!

Asked By: Stefan Vukovic



In user defined views(ex: APIView), you have to paginate queryset and return paginated response.
and restframework cannot find which model and fields you are using in APIView, so instead of APIView use ListCreateAPIView

change BookApiList view like this:

from rest_framework import generics

class BookApiList(generics.ListCreateAPIView):
    queryset = Book.objects.all()
    serializer_class = BookSerializer
Answered By: Mukhtor