tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.58k stars 378 forks source link

How tortoise implements the same functionality as SerializerMethodField in DRF? #1545

Open rubbish822 opened 8 months ago

rubbish822 commented 8 months ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like

from rest_framework import serializers
from drf_spectacular.utils import extend_schema_field

class UserSerializer(serializers.ModelSerializer):
    full_name = serializers.SerializerMethodField(read_only=True)

    @extend_schema_field(serializers.CharField)
    def full_name(self, obj):
        return f'{obj.first_name}:{obj.id}'

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context about the feature request here.