Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django管理员多次计数问题_Python_Django_Postgresql_Django Admin - Fatal编程技术网

Python Django管理员多次计数问题

Python Django管理员多次计数问题,python,django,postgresql,django-admin,Python,Django,Postgresql,Django Admin,我对Django Admin重复调用count方法有问题。这是我的密码 class AdminPaginator(Paginator): @property def count(self): cursor = connection.cursor() cursor.execute("SELECT reltuples FROM pg_class WHERE relname = %s", [query.model._meta

我对Django Admin重复调用
count
方法有问题。这是我的密码

class AdminPaginator(Paginator):
    
    @property
    def count(self):
        cursor = connection.cursor()
        cursor.execute("SELECT reltuples FROM pg_class WHERE relname = %s", [query.model._meta.db_table])
        count = int(self.cursor.fetchone()[0])
        return count
。。。来自管理模型的代码

list_per_page = 50
show_full_result_count = False
paginator = AdminPaginator


def get_queryset(self, request):
    """
    Overrides default query to exclude inactive entities.
    """
    qs = super().get_queryset(request)
    active_entities = qs.filter(is_active=False)

    return qs.exclude(id__in=active_entities)
Django调用了4次
count
方法,我不知道为什么。

谢谢你的帮助

您可以将@property替换为@cached_property

了解信号在我的情况下有何帮助?