I would like to define a default manager for MyModel that always
filters all records (when the model is accessed from anywhere in my
application) based on data from the request:

e.g. on the lines of:

class MyModelManager(models.Manager):
    #override default
    def get_query_set(self, request):
        if request.foo == bar:
            return super(MyModelManager, self).get_query_set()
        return MyModel.objects.filter(spam = eggs)


class MyModel(models.Model):
    ...
    objects = MyModelManager()


However I get the error:

Django Version: 1.2.1
Exception Type: TypeError
Exception Value:
Error when calling the metaclass bases
    get_query_set() takes exactly 2 arguments (1 given)


So its clear that get_query_set() cannot take the request inserted
there... but how else can I access the request inside the above model
Manager class?

(Note that I don't want to define an extra method that needs to be
appended onto the MyModels.objects.zzz type of chained calls  - such
as the solution posted at http://osdir.com/ml/django-users/2010-02/msg00819.html
- as I would then have to make these changes throughout the
application, and also remember to add such a method to all future
code.)

Thanks
Derek

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to