Overload the 'last', 'first', and 'count' queryset methods to work for the TypedObjectManager.

This commit is contained in:
Tehom 2016-10-04 02:40:24 -04:00 committed by Griatch
parent 23e658acf9
commit ae5848dd0b

View file

@ -557,6 +557,44 @@ class TypeclassManager(TypedObjectManager):
"""
return super(TypedObjectManager, self).all().filter(db_typeclass_path=self.model.path)
def first(self):
"""
Overload method to return first match, filtering for typeclass.
Returns:
object (object): The object found.
Raises:
ObjectNotFound: The exact name of this exception depends
on the model base used.
"""
return super(TypedObjectManager, self).filter(db_typeclass_path=self.model.path).first()
def last(self):
"""
Overload method to return last match, filtering for typeclass.
Returns:
object (object): The object found.
Raises:
ObjectNotFound: The exact name of this exception depends
on the model base used.
"""
return super(TypedObjectManager, self).filter(db_typeclass_path=self.model.path).last()
def count(self):
"""
Overload method to return number of matches, filtering for typeclass.
Returns:
integer : Number of objects found.
"""
return super(TypedObjectManager, self).filter(db_typeclass_path=self.model.path).count()
def _get_subclasses(self, cls):
"""
Recursively get all subclasses to a class.