[Answered ]-How to modify timestamp format in Django Rest Framework fields

1👍

class PostSerializer(serializers.ModelSerializer):
    str_timestamp = serializers.SerializerMethodField(
        method_name="get_str_timestamp"
    )    

    class Meta:
        model = Post
        fields = '__all__'

    def get_str_timestamp(self, obj: Post):
        return obj.timestamp.strftime('%b %d %Y, %I:%M %p')
👤Nikita

Leave a comment