Issue with serializers.ListSerializer in Web Brosable API

79 views
Skip to first unread message

edin buce

unread,
Apr 28, 2023, 5:57:47 PM4/28/23
to Django REST framework
I have this serializes 
class PostSerializer(serializers.ModelSerializer):

class Meta:
model = Post
fields = ('name', 'html_code', 'order')


class PostListSerializer(serializers.ListSerializer):
child = PostSerializer()

def create(self, validated_data):
....

and I am sending this payload to create multiple entries 
[
    {
        "name""aaaa 2",
        "order" : 3,
        "html_code""<p>test</p>"
    },
    {
        "name""vvffv",
        "order" : 3,
        "html_code""<p>test</p>"
    }
]
This works fine and entries are created.
But I have an issue when i try to view that endpoint in the Web Browsable Api and i have this error 
AttributeError: 'PostListSerializer' object has no attribute 'fields'

kofi akrong

unread,
Apr 28, 2023, 7:21:46 PM4/28/23
to Django REST framework
From the listviewserializer you are not showing any fields so obvioiusly, you have to define a class meta: and put fields to show
Reply all
Reply to author
Forward
0 new messages