1. Luke Plant
  2. django-piston

Commits

Mads Sülau Valstorp Jørgensen  committed 1a444cb

Refactored get_queryset to accept and recieve arguments.

  • Participants
  • Parent commits 0764bde
  • Branches default

Comments (0)

Files changed (1)

File piston/handler.py

View file
     def has_model(self):
         return hasattr(self, 'model')
     
-    def get_queryset(self):
+    def get_queryset(self, *args, **kwargs):
         """
         Returns the queryset on which all operations operate.
         
         """
         return self.model.objects
     
-    queryset = property(get_queryset)
-    
     def exists(self, **kwargs):
         if not self.has_model():
             raise NotImplementedError
         
         try:
-            self.queryset.get(**kwargs)
+            self.get_queryset(*args, **kwargs).get(**kwargs)
             return True
         except self.model.DoesNotExist:
             return False
         if not self.has_model():
             raise NotImplementedError
         
-        return self.queryset.filter(*args, **kwargs)
+        return self.get_queryset(*args, **kwargs).filter(*args, **kwargs)
     
     def create(self, request, *args, **kwargs):
         if not self.has_model():
         attrs = self.flatten_dict(request.POST)
         
         try:
-            inst = self.queryset.get(**attrs)
+            inst = self.get_queryset(*args, **kwargs).get(**attrs)
             raise ValueError("Already exists.")
         except self.model.DoesNotExist:
             inst = self.model(attrs)
         if not self.has_model():
             raise NotImplementedError
         
-        inst = self.queryset.get(*args, **kwargs)
+        inst = self.get_queryset(*args, **kwargs).get(*args, **kwargs)
         print "must update instance", inst, "with", request.PUT
         
         return "I can't do this yet."