Hia Folks, I recently made a web app with Django where I present a list of Jobs a user can execute. I make a list of Jobs based on user and group memberships. I use contrib.auth for the memberships. I make the list with this: -- snip -- class JobManager(models.Manager): def jobsByUser(self, username): lookup = models.Q(user__username__icontains=username) | \ models.Q(group__user__username__icontains=username) return Job.objects.filter(lookup).distinct('name') -- snip -- This works like a charm.
I added a search box and I am able to search on any of the properties of a Job. Since I recently added the group memberships part I used to search only in the Jobs a user had permissions to. I now want to expand the search to include the group memberships. This is the part I use to create the list: --snip-- @login_required def joblist(request): """ haalt de jobs voor de user uit de database en laat ze zien""" query = request.GET.get('q','') if query: # filter op: Job.name, Job.description, Job.host, Job.type, Job.user qset = ( Q(name__icontains=query) | Q(description__icontains=query) | Q(host__icontains=query) | Q(type__name__icontains=query)) joblist = Job.objects.filter(qset,user__username__icontains=request.user.username) #joblist = Job.objects.filter(qset,user__username__icontains=request.user.username, group__user__username__icontains=request.user.username) else: joblist = Job.objects.jobsByUser(request.user.username) jobtable = JobTable( joblist,) return render_to_response('joblist.html', {'username':request.user.username, 'table':jobtable} ) --snip-- The commented line is my last attempt to include the group memberships, but this doesn't work. I think I'm missing a very simple solution here. In the Django Admin part I can select users and groups that have access to a Job. I want to be able to search not just in the Jobs that a user has access to, but also with group memberships. I would greatly appreciate any help any of you can offer. Regards, Mark P.S. If turns out to be a double post, I'm sorry -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Chxou0nSBN8J. To post to this group, send email to django-users@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.