1👍
✅
You have to call the methods on an instance of the serializer (not the class itself):
serializer = AccountSerializer()
fields = serializer.get_fields().keys()
0👍
I have found this one-liner using the serializer class which works fine for me:
fields = AccountSerializer.Meta.fields # return a tuple of strings
As a note: I find the method by SofienM can give more information out of the object.
- [Answered ]-Dynamic choices in Foreignkey Field in Django Rest Framework
- [Answered ]-What sort of Python work on Windows stops mod-wsg/Apache's ability to deal with multiple requests?
- [Answered ]-Can I prevent Django user login sessions from expiring?
Source:stackexchange.com