PackageManager allows chaining

This commit is contained in:
volpino 2012-05-05 10:03:02 +02:00
parent a145d8a4f6
commit 84b2a1917a

View File

@ -6,7 +6,8 @@ from django.db import models
from djeuscan.helpers import xint
class PackageManager(models.Manager):
class PackageMixin(object):
def n_packaged(self):
res = self.aggregate(models.Sum('n_packaged'))['n_packaged__sum']
return xint(res)
@ -120,3 +121,12 @@ class PackageManager(models.Manager):
)
return res
class PackageQuerySet(models.query.QuerySet, PackageMixin):
pass
class PackageManager(models.Manager, PackageMixin):
def get_query_set(self):
return PackageQuerySet(self.model, using=self._db)