Untitled
unknown
plain_text
3 years ago
1.5 kB
10
Indexable
class GameDetailSerializer(serializers.ModelSerializer):
price = serializers.SerializerMethodField()
# TODO реализовать систему скидок
discount = serializers.IntegerField(default=0)
# TODO продумать систему оценок
is_bought = serializers.BooleanField(default=False)
is_favorite = serializers.BooleanField(default=False)
system_requirements = SystemRequirementSerializer(many=True, read_only=True)
genres = GenreGamesSerializer(many=True, read_only=True)
dlcs = ProductSerializer(many=True, read_only=False)
langs = ref_serializers.ProductLanguageSerializer(many=True, read_only=False)
genres = GenreGamesSerializer(many=True, read_only=True)
def get_price(self, obj):
try:
offer = ProductOffer.objects.get(product=obj).offer
except ProductOffer.DoesNotExist:
return None
return offer.price.amount
class Meta:
model = Product
fields = (
'id',
'name',
'release_date',
'genres',
'price',
'discount',
'is_bought',
'is_favorite',
'description',
'about',
'age',
'adult',
'adult',
'status',
'type',
'developers_uuid',
'publishers_uuid',
'dlcs',
'langs',
'system_requirements',
)Editor is loading...