J'ai une classe comme ci-dessousComment obtenir les noms de propriété de super-classe dans la sous classe python
class Paginator(object):
@cached_property
def count(self):
some_implementation
class CachingPaginator(Paginator):
def _get_count(self):
if self._count is None:
try:
key = "admin:{0}:count".format(hash(self.object_list.query.__str__()))
self._count = cache.get(key, -1)
if self._count == -1:
self._count = self.count # Here, I want to get count property in the super-class, this is giving me -1 which is wrong
cache.set(key, self._count, 3600)
except:
self._count = len(self.object_list)
count = property(_get_count)
Comme indiqué dans le commentaire ci-dessus, self._count = <expression>
devrait obtenir la propriété de comptage en super-classe. Si c'est la méthode, nous pouvons l'appeler comme ceci super(CachingPaginator,self).count()
AFAIK. J'ai référé de nombreuses questions à SO, mais rien de tout cela ne m'a aidé. Quelqu'un peut-il m'aider dans ce domaine.
Et avez-vous essayé 'super (CachingPaginator, auto) .count'? –
Ou, si vous êtes sur python 3: 'super(). Count' –
@TheBrewmaster Je suis sur python 2.7 mate ... –