Selwin Ong committed 275606d

Added a get_generation utility function.

  • Participants
  • Parent commits 83a3c8e
  • Branches get_generation

Comments (0)

Files changed (1)

     tables will not be invalidated properly.  Use Carefully."""
+def resolve(x):
+    """Returns a model's database table name if argument is a django model."""
+    if isinstance(x, basestring):
+        return x
+    return x._meta.db_table
 def invalidate(*tables, **kwargs):
     """Invalidate the current generation for one or more tables.  The arguments
     can be either strings representing database table names or models.  Pass in
     backend = get_backend()
     db = kwargs.get('using', 'default')
-    def resolve(x):
-        if isinstance(x, basestring):
-            return x
-        return x._meta.db_table
     if backend._patched:
         for t in map(resolve, tables):
             backend.keyhandler.invalidate_table(t, db)
+def get_generation(*tables, **kwargs):
+    """Get the generation key for one or more models. Similar to the
+    ``invalidate`` function, the user may choose to pass in string
+    representation of database tables names or django models."""
+    backend = get_backend()
+    if backend._patched:
+        table_names = (resolve(table) for table in tables)
+        return backend.keyhandler.get_generation(*table_names, **kwargs)
 def get_tables_for_query(query):
     Takes a Django 'query' object and returns all tables that will be used in