From ae5848dd0ba0ee0fcf50c6f363821300a972eab2 Mon Sep 17 00:00:00 2001 From: Tehom Date: Tue, 4 Oct 2016 02:40:24 -0400 Subject: [PATCH] Overload the 'last', 'first', and 'count' queryset methods to work for the TypedObjectManager. --- evennia/typeclasses/managers.py | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/evennia/typeclasses/managers.py b/evennia/typeclasses/managers.py index a622948d1c..699d031ef6 100644 --- a/evennia/typeclasses/managers.py +++ b/evennia/typeclasses/managers.py @@ -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.