привет, ребята ia newb ie и изучение django -framework и построение rest-api, я застрял на этой ошибке. Это дает мне ошибку в venv \ lib \ site-packages \ rest_framework \ serializers.py в get_fields, строка 1020. и говорит, что Class RatingSerializers отсутствует атрибут "Meta.model".
Я выполнил всю миграцию и makemigration
Exception Type: AssertionError
Exception Value:
Class RatingSerializers missing "Meta.model" attribute
urls.py
from django.contrib import admin
from django.urls import path
from rest_framework import routers
from django.conf.urls import include
from .views import MovieViewSet, RatingViewSet
router = routers.DefaultRouter()
router.register('movies', MovieViewSet)
router.register('ratings', RatingViewSet)
urlpatterns = [
path('', include(router.urls)),
]
models.py
from django.db import models
from django.contrib.auth.models import User
from django.core.validators import MaxValueValidator, MinValueValidator
class Movie(models.Model):
title = models.CharField(max_length=32)
description = models.TextField(max_length=500)
class Rating(models.Model):
movie = models.ForeignKey(Movie, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
stars = models.IntegerField(validators=[MinValueValidator(1), MaxValueValidator(5)])
class Meta:
unique_together = (('user', 'movie'),)
index_together = (('user', 'movie'),)
serializer.py
from rest_framework import serializers
from .models import Movie, Rating
class MovieSerializers(serializers.ModelSerializer):
class Meta:
model: Movie
fields = ('id', 'title', 'description')
class RatingSerializers(serializers.ModelSerializer):
class Meta:
model: Rating
fields = ('id', 'stars', 'user', 'movie')
views.py
from django.shortcuts import render
from rest_framework import viewsets
from .models import Movie, Rating
from .serializers import MovieSerializers, RatingSerializers
class MovieViewSet(viewsets.ModelViewSet):
queryset = Movie.objects.all()
serializer_class = MovieSerializers
class RatingViewSet(viewsets.ModelViewSet):
queryset = Rating.objects.all()
serializer_class = RatingSerializers
понятия не имею, что не так с ней.