On 9/1/06, Gabriel Puliatti <[EMAIL PROTECTED]> wrote:
>
> Hello. I have an application in which a list should be filtered
> depending on what groups a user belongs, since the application is a
> homework list, and the list must only contain the classes the user
> (student) is enrolled.
>
> I know I should do this using filter, but I have no idea how to get
> the list of groups the current, logged in user is a member of, and
> then making that into a filter. Anyone have any tips?
>
> -----
> def index(request):
>     object_list = Homework.objects.order_by('-duedate')[:100]
>     t = loader.get_template('homework/homework_list.html')
>     c = Context
>         'object_list': object_list,
>     })
>     return HttpResponse(t.render(c))
> -----
>
> This is the relevant function, in which the latest 100 homework
> entries are passed and then rendered by a template.
>
> If anyone has any tips on how to do this filtering by user group, then
> please do. Help is much appreciated at this point, considering I am a
> newbie. :P

You must have some sort of relation set up between Homework and User
and/or Group, don't you? So it will likely be something like
request.user.homework_set.all().order_by("-duedate"), unless you set a
related_name on your ForeignKeyField or ManyToManyField.

Or, if you are relating Homework to Group, then you might want
something like request.user.groups.homework_set.all().order_by("-duedate")

(It's late, I haven't sanity-checked the above.)
-- 
This message has been scanned for memes and
dangerous content by MindScanner, and is
believed to be unclean.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to