Django Rest Api Annotate group by Фильтр, показывающий ошибку? - PullRequest
0 голосов
/ 18 марта 2020

Эта ошибка появляется при вводе http://127.0.0.1: 8000 / api / student / этот URL enter image description here

Моя база данных:

enter image description here

posts / models.py

from django.db import models

class Student(models.Model):

lname = models.CharField(max_length=50)
fname=models.CharField(max_length=50)



 def __str__(self):
   return self.lname

публикаций / сериализаторов. py (webapp)

from rest_framework import serializers
from . import models


class StudentSerializer(serializers.ModelSerializer):

class Meta:
    fields = ('lname','fname',)
    model = models.Student 

posts \ filters.py (webapp)

from django_filters import rest_framework as filters

from .models import Student


class StudentFilter(FilterSet):
    total = filters.NumberFilter(name='total')
    class Meta:
    model = Student
    fields = ['lname','fname','total',]#other fields

posts \ views.py (webapp)

from rest_framework import generics
from django.db.models import Count

from .models import Post,Student,Exam,Sample
from .serializers import PostSerializer,StudentSerializer,ExamSerializer,SampleSerializer
from django_filters.rest_framework import DjangoFilterBackend
#import django_filters.rest_framework
from django.db import connection


class StudentList(generics.ListAPIView):

   serializer_class = StudentSerializer
   def get_queryset(self):
   return 
Student.objects.all().values('fname').annotate(total=Count('fname')).order_by('total') 

posts \ urls.py (webapp)

from django.urls import path

from . import views

urlpatterns = [
           path('', views.PostList.as_view()),
           path('<int:pk>/', views.PostDetail.as_view()),
           path('student/',views.StudentList.as_view()),
           path('exam/',views.ExamList.as_view()),
          path('sam/',views.SampleList.as_view())
]   

SampleProject (urls.py)

from django.contrib import admin
from django.urls import include, path


urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include('posts.urls')),
]
 I got output in the shell but I couldn't get the same value in the browser (API)

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...