解决使用drf-haystack报错ImportError: cannot import name get_count

如果在配置完haystack并启动程序后,出现如下异常,是因为drf-haystack还没有适配最新版本的REST framework框架
报错源码

可以通过修改REST framework框架代码,补充_get_count函数定义即可
文件路径 虚拟环境下的
lib/python3.6/site-packages/rest_framework/pagination.py

def _get_count(queryset):
    """
    Determine an object count, supporting either querysets or regular lists.
    """
    try:
        return queryset.count()
    except (AttributeError, TypeError):
        return len(queryset)
posted @ 2018-06-27 13:29  fanlei5458  阅读(410)  评论(0编辑  收藏  举报