Dynamic queryset for a collection

0 views
Skip to first unread message

Zain Memon

unread,
Jan 27, 2009, 8:43:45 PM1/27/09
to Django REST interface
Hello,

I'd like to have the queryset for a collection be dynamically
generated based on the request.

I require authentication for all API requests and each authenticated
users can only access a subset of the resources being exposed; so,
doing a GET on resource/ should only return a list of resources that
the user has access to.

I figured the best way to do this would be to dynamically set the
queryset of the Collection based on the username on the request. It
looks like the queryset has to be passed into init, and that queryset
is passed into the responder, so the queryset would have to be
correctly set in the init method (before we have the request object).
Does anyone have any ideas around this? Or any other suggestions on
how I can accomplish a dynamic queryset?

Kevin Damm

unread,
Jan 27, 2009, 11:20:16 PM1/27/09
to django-res...@googlegroups.com
Just a suggestion, not sure if this is the best way to go about it,
but you could create a custom Middleware class, override the
process_request method, and insert it in your MIDDLEWARE_CLASSES list
(in settings.py), somewhere after the AuthenticationMiddleware.

- Kevin
Reply all
Reply to author
Forward
0 new messages