40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
from import_export.admin import ImportExportModelAdmin
|
|
from django.contrib import admin
|
|
# from django.core.cache import cache
|
|
# from django.core.paginator import Paginator
|
|
from . import models
|
|
from . import resources
|
|
|
|
|
|
# # Modified version of a GIST I found in a SO thread
|
|
# # cfr. http://masnun.rocks/2017/03/20/django-admin-expensive-count-all-queries/
|
|
# class CachingPaginator(Paginator):
|
|
# def _get_count(self):
|
|
# if not hasattr(self, "_count"):
|
|
# self._count = None
|
|
# if self._count is None:
|
|
# try:
|
|
# key = "adm:{0}:count".format(hash(self.object_list.query.__str__()))
|
|
# self._count = cache.get(key, -1)
|
|
# if self._count == -1:
|
|
# self._count = super().count
|
|
# cache.set(key, self._count, 60)
|
|
# except:
|
|
# self._count = len(self.object_list)
|
|
# return self._count
|
|
# count = property(_get_count)
|
|
|
|
# # Main reusable Admin class for only viewing
|
|
# class ViewAdminMixin(admin.ModelAdmin):
|
|
# def has_add_permission(self, request):
|
|
# return False
|
|
#
|
|
# def has_change_permission(self, request, obj=None):
|
|
# return False
|
|
#
|
|
# def has_delete_permission(self, request, obj=None):
|
|
# return False
|
|
|
|
# --------------- FINE PREFISSO TEMPLATE ---------------
|
|
raise Exception('Fai girare sqldes2django oppure elimina questa eccezione.')
|