mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-27 04:47:04 -05:00
30 lines
826 B
Python
30 lines
826 B
Python
from rest_framework import serializers
|
|
from .models import Review
|
|
from apps.accounts.serializers import UserSerializer
|
|
|
|
class ReviewSerializer(serializers.ModelSerializer):
|
|
user = UserSerializer(read_only=True)
|
|
|
|
class Meta:
|
|
model = Review
|
|
fields = [
|
|
"id",
|
|
"user",
|
|
"content_type",
|
|
"object_id",
|
|
"rating",
|
|
"text",
|
|
"is_public",
|
|
"helpful_votes",
|
|
"created_at",
|
|
"updated_at",
|
|
]
|
|
read_only_fields = ["id", "user", "helpful_votes", "created_at", "updated_at"]
|
|
|
|
def validate(self, data):
|
|
"""
|
|
Check that rating is between 1 and 5.
|
|
"""
|
|
# Rating is already validated by model field validation but explicit check is good
|
|
return data
|