Make ListSerializer() a function on an object like serializer()
See original GitHub issueWhat is your use-case and why do you need this feature? Hey,
I just migrated to 1.0.0-RC and had to change my list serializations from MyClass.serializer().list
to ListSerializer(MyClass.serializer())
. I thought ListSerializer
is a class and I need to create an instance of it, but it’s actually a method, what’s quite confusing.
I think this new solution is quite hard to find, if you don’t know it exists.
Describe the solution you’d like
I’m wondering why it’s not simply MyClass.listSerializer()
or just like before MyClass.serializer().list()
? You can add similar methods for Sets
and Maps
. It’s way more straight-forward to understand and is consistent with how you use the “default” serializer.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Serializers - Django REST framework
Serializers allow complex data such as querysets and model ... In some cases the .create() and .update() method names may not be meaningful....
Read more >django - How to use ListSerializer with a ModelSerializer?
The serializer.data property is only valid if you have a saved an instance to the serializer. Either call serializer.save() or use ...
Read more >Serializers - Django REST framework - Tom Christie
Serializers allow complex data such as querysets and model instances to be converted to native Python datatypes that can then be easily rendered...
Read more >Multiple Create: 'ListSerializer' object is not iterable #5502
I am trying to make a ViewSet that allows multiple-creation. It does actually work, however it throws an error in my logs.
Read more >ListSerializer -- Classy DRF
Detailed descriptions, with full methods and attributes of ListSerializer Django REST Framework class.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think the reason behind the change is to follow the philosophy of object-oriented programming.
serializer.list
implies that the single object serializer has a list serializer as a member of it, which sounds somewhat weird.ListSerializer(serializer)
implies that the list serializer is containing a single object serializer, and it sounds more plausible.You could think of it as a class constructor, indeed it is.
calling a class constructor and top-level method is no different in Kotlin so where is your confusion coming from?
That’s pretty neat. Seems for me then it was only a migration issue.
Thanks for your explanation, very helpful, closing it then 👍