Fix Django's QuerySet.delete() behavior for models that use "invalid"

Signed-off-by: James Ren <jamesren@google.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@4276 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/frontend/afe/model_logic.py b/frontend/afe/model_logic.py
index 1a40ce6..59e5ffb 100644
--- a/frontend/afe/model_logic.py
+++ b/frontend/afe/model_logic.py
@@ -530,7 +530,24 @@
             getattr(base_object, related_list_name).append(related_object)
 
 
-class ValidObjectsManager(ExtendedManager):
+class ModelWithInvalidQuerySet(dbmodels.query.QuerySet):
+    """
+    QuerySet that handles delete() properly for models with an "invalid" bit
+    """
+    def delete(self):
+        for model in self:
+            model.delete()
+
+
+class ModelWithInvalidManager(ExtendedManager):
+    """
+    Manager for objects with an "invalid" bit
+    """
+    def get_query_set(self):
+        return ModelWithInvalidQuerySet(self.model)
+
+
+class ValidObjectsManager(ModelWithInvalidManager):
     """
     Manager returning only objects with invalid=False.
     """