class BookSerializerNew(ModelSerializer): its_a_2 = SerializerMethod() def get_its_a_2(self, instance): return instance.its_a_2() class Meta: model = Book fields = ['its_a_2', ]
class BookSerializerNew(ModelSerializer): its_a_2 = SerializerMethod(method_name="my_special_method_name") @staticmethod def my_special_method_name(instance): return instance.its_a_2() class Meta: model = Book fields = ["its_a_2"]
class BookSerializerNew(ModelSerializer): its_a_2 = SerializerMethod() @staticmethod def get_its_a_2(instance): return instance.its_a_2() class Meta: model = Book fields = ["its_a_2"]
class BookSerializer(ModelSerializer): book_type = SerializerMethod() def get_book_type(self, instance): return instance.book_type_display() class Meta(): model = Book fields = [ 'id', 'name', 'synopsis', 'book_type', 'pages', 'date_created' ]
class BookSerializer(ModelSerializer): book_type = SerializerMethod(method_name='my_book_type') @staticmethod def my_book_type(instance): return instance.book_type_display() class Meta(): model = Book fields = [ 'id', 'name', 'synopsis', 'book_type', 'pages', 'date_created' ]
class BookSerializer(ModelSerializer): book_type = SerializerMethod(method_name="my_book_type") @staticmethod def my_book_type(instance): return instance.book_type_display() class Meta: model = Book fields = [ "id", "name", "synopsis", "book_type", "pages", "date_created" ]