Add a shortcut to obtain the instance of a possibly existing cnfvar
authorPlamen Dimitrov <plamen.dimitrov@intra2net.com>
Thu, 21 Apr 2022 07:05:35 +0000 (10:05 +0300)
committerPlamen Dimitrov <plamen.dimitrov@intra2net.com>
Wed, 11 May 2022 06:25:19 +0000 (09:25 +0300)
This is added in the cnf list query mixin which is where we have
all shortcut, syntactic sugar, and ease of use methods.

src/cnfvar/model.py

index 827ff99..168f5db 100644 (file)
@@ -929,6 +929,10 @@ class CnfListQueryingMixin(BaseCnfList):
         """Shortcut method for getting the first item with a given instance."""
         return self.with_instance(instance).first(default=default)
 
+    def highest_instance(self):
+        """Shortcut method for getting the next instance in a list of items."""
+        return max([c.instance for c in self]) if len(self) > 0 else -1
+
 
 ###############################################################################
 # PUBLIC CLASSES