admin.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:gougo 作者: amaozhao 项目源码 文件源码
def subclass_view(self, request, path):
        """
        Forward any request to a custom view of the real admin.
        """
        ct_id = int(request.GET.get('ct_id', 0))
        if not ct_id:
            # See if the path started with an ID.
            try:
                pos = path.find('/')
                if pos == -1:
                    object_id = long(path)
                else:
                    object_id = long(path[0:pos])
            except ValueError:
                raise Http404("No ct_id parameter, unable to find admin subclass for path '{0}'.".format(path))

            ct_id = self.model.objects.values_list('polymorphic_ctype_id', flat=True).get(pk=object_id)

        real_admin = self._get_real_admin_by_ct(ct_id)
        resolver = RegexURLResolver('^', real_admin.urls)
        resolvermatch = resolver.resolve(path)  # May raise Resolver404
        if not resolvermatch:
            raise Http404("No match for path '{0}' in admin subclass.".format(path))

        return resolvermatch.func(request, *resolvermatch.args, **resolvermatch.kwargs)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号