Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get view's name in serializer

I have a serilizer. I have overridden the to_representation method of the serializer. I want to use the view name for which the serializer code has been invoked. I tried the following::

self.context['view'].__class__

This returns me the following::

<class 'search.api.v1.views.JobSearchList'>

However, I just want the name of the view class. i.e. JobSearchList

Any idea how I can go about doing this?

like image 738
Animesh Sharma Avatar asked Sep 13 '25 12:09

Animesh Sharma


1 Answers

I can get the name by

self.context['view'].__class__.__name__
# or type(self.context['view']).__name__  something like that.
like image 143
soooooot Avatar answered Sep 15 '25 02:09

soooooot