Karol,
Check this out:
http://code.djangoproject.com/wiki/CookBookThreadlocalsAndUser
I used this so I could get the current user anywhere. My use for this is to
know the request.user when the post_save signal fires so I can log the
attributes of a model each time it's saved and know who did it
Ok, I think I have sorted out my queryset problem, I wrote a custom
manager:
class UserBranchModelManager(models.Manager):
def for_request(self, request):
if settings.DO_BRANCH_FILTER:
return super(UserBranchModelManager,
self).get_query_set().filter(branch__pk = request.us
Sorry one more thing, the above filters my querysets but then comes
the get() method on each model. I use urls with pk's so a user could
just try to change the url to a pk that does not belong to them and
view it. To filter this out I run yet another function:
def relation_branch_validation(reques
Just so you have an idea what I am trying to do. :)
I have a custom middleware that adds a userBranchID variable to each
request according to the users branch in the User model.
Now in each view when I use any queryset I have to do the following:
def filter_branch(request, queryset):
if settin
Hi Shawn,
I use Managers often to limit my querysets and add additional fields
that I want dynamically calculated using sql. I just don't see how I
can get the request object to the models.Manager so it knows what to
filter by (user.uid). :(
I know I could do a filter in each view
queryset.object
It looks like you might want to create a custom Manager class. As you alluded
to, you definitely don't want to have to assume that every function that
touches your models is doing all the required checking.
http://docs.djangoproject.com/en/1.1/topics/db/managers/
I didn't really know what a Man
the
users site to the session as it's easy to manipulate a session
variable.
Is there any form of middleware for models so that you can pass the
request object to it?
Any advice will be highly appreciated.
Regards
--
You received this message because you are subscribed to the Google Groups
7 matches
Mail list logo