cineclub-site/server/myapi/serializers.py

36 lines
938 B
Python

from rest_framework import serializers
from .models import Film
class MoreFieldsModelSerializer(serializers.ModelSerializer):
def get_field_names(self, declared_fields, info):
expanded_fields = super().get_field_names(declared_fields, info)
if getattr(self.Meta, "extra_fields", None):
return expanded_fields + self.Meta.extra_fields
else:
return expanded_fields
class FilmSerializer(serializers.ModelSerializer):
class Meta:
model = Film
fields = "__all__" #
class FromTmdbFilmSerializer(serializers.ModelSerializer):
class Meta:
model = Film
fields = [
"title",
"actors",
"director",
"duration",
"synopsis",
"origin_country",
"release_year",
"is_in_color",
"poster_link",
"imdb_id",
"tmdb_id",
]