Django Rest Api Аннотировать группу с помощью фильтра, показывающего ошибку?
Эта ошибка возникает при вводе http://127.0.0.1:8000/api/student/ этого URL-адреса
Моя база данных:
сообщения / 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
сообщения / serializers.py (веб-приложение)
from rest_framework import serializers
from . import models
class StudentSerializer(serializers.ModelSerializer):
class Meta:
fields = ('lname','fname',)
model = models.Student
сообщения \filters.py(веб-приложение)
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
сообщения \views.py(веб-приложение)
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')
сообщения \urls.py(веб-приложение)
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)