sbt-idp/cope2n-api/fwd_api/response/SubscriptionResponse.py

31 lines
982 B
Python
Raw Permalink Normal View History

2023-11-30 11:19:06 +00:00
from rest_framework import serializers
from fwd_api.models import SubscriptionRequest, Subscription
2023-12-15 05:43:19 +00:00
from fwd_api.utils.date import FORMAT
2023-11-30 11:19:06 +00:00
class SubscriptionResponse(serializers.Serializer):
id = serializers.IntegerField(read_only=True)
current_token = serializers.IntegerField(required=False)
limit_token = serializers.IntegerField(required=False)
start_at = serializers.DateTimeField(required=False, format=FORMAT.DD_MM_YYYY_HHMMSS.value)
expired_at = serializers.DateTimeField(required=False, format=FORMAT.DD_MM_YYYY_HHMMSS.value)
plan_code = serializers.SerializerMethodField()
def create(self, validated_data):
"""
Create and return a new `Snippet` instance, given the validated data.
"""
return SubscriptionRequest.objects.create(**validated_data)
def update(self, instance, validated_data):
return instance
def get_plan_code(self, obj: Subscription):
return obj.pricing_plan.code