예제 #1
0
        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', ]
예제 #2
0
        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"]
예제 #3
0
        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"]
예제 #4
0
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'
        ]
예제 #5
0
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'
        ]
예제 #6
0
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"
        ]