Add annotate method to TypedManager to filter by typeclass appropriately.

This commit is contained in:
Tehom 2018-06-28 08:23:52 -04:00
parent 8d8adbbc77
commit df866fb3f3

View file

@ -619,6 +619,18 @@ class TypeclassManager(TypedObjectManager):
"""
return super(TypeclassManager, self).filter(db_typeclass_path=self.model.path).count()
def annotate(self, *args, **kwargs):
"""
Overload annotate method to first call .all() to filter on typeclass before annotating.
Args:
*args (any): Positional arguments passed along to queryset annotate method.
**kwargs (any): Keyword arguments passed along to queryset annotate method.
Returns:
Annotated queryset.
"""
return super(TypeclassManager, self).filter(db_typeclass_path=self.model.path).annotate(*args, **kwargs)
def _get_subclasses(self, cls):
"""
Recursively get all subclasses to a class.