I\'m using a middleware to get the currently logged in user in my views and models. This helps me to for example return only the objects created or assigned to the logged-in
Ignoring the thread local sideshow, your problem is probably related to the fact that the AnonymousUser
object is not really a User
model instance. Querying the database with this object may not get you very far. You will want to check for authenticated users at some point, either in the view:
if request.user.is_authenticated():
Project.objects.for_user(request.user)
Or in your manager method:
def for_user(self, user):
if user.is_authenticated():
return self.get_query_set().filter(projectmembership__member=user)
else:
return self.get_query_set().none()