Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Django Rest Framework. What is queryset and serializer_class?

Let’s say I have the following viewset:

class CategoryViewSet(viewsets.ModelViewSet):
    queryset = Category.objects.all()
    serializer_class = CategorySerializer

I am wondering what does the queryset and serializer_class do here? I can assume queryset is about how the models’ order will be displayed (such as ordering, filtering and so on), but I may be wrong. Please correct me, and, if possible give broad explanation.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

queryset this to select data from database, you can select all data or apply filter or what you want, in more basic way.. where to write your database query using Django ORM

serializer where the queryset will serialize like convert it to json object to use it in response for example, because some ORM query will return QuerySet not a json object

this a basic explained for both, you can check for more details in Django RestFramework Serializer

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading