在序列化程序中获取视图的名称
Get view's name in serializer
我有一个消毒器。我已经覆盖了序列化程序的 to_representation
方法。我想使用已为其调用序列化程序代码的视图名称。我尝试了以下内容::
self.context['view'].__class__
这个 returns 我以下::
<class 'search.api.v1.views.JobSearchList'>
不过,我只想要视图的名称class。即 JobSearchList
知道我该怎么做吗?
我可以通过
得到名字
self.context['view'].__class__.__name__
# or type(self.context['view']).__name__ something like that.
我有一个消毒器。我已经覆盖了序列化程序的 to_representation
方法。我想使用已为其调用序列化程序代码的视图名称。我尝试了以下内容::
self.context['view'].__class__
这个 returns 我以下::
<class 'search.api.v1.views.JobSearchList'>
不过,我只想要视图的名称class。即 JobSearchList
知道我该怎么做吗?
我可以通过
得到名字self.context['view'].__class__.__name__
# or type(self.context['view']).__name__ something like that.