Re: Filter on related model problem...

2007-08-15 Thread [EMAIL PROTECTED]
Yes, you have to sort by the column you are regrouping--the regrouping doesn't change the position of the rows. Good example here: http://www.djangoproject.com/documentation/templates/ On Aug 14, 9:18 pm, Carl Karsten <[EMAIL PROTECTED]> wrote: > Collin Grady wrote: > > Regroup generates a list

Re: Filter on related model problem...

2007-08-14 Thread Carl Karsten
Collin Grady wrote: > Regroup generates a list of dicts with two keys - grouper (the value > of the field you're grouping by) and list (the list of objects that > match that) > > So in this case, you get entries like {'grouper': , > 'list': [, , ...]} :) > > why is it call regroup and not jus

Re: Filter on related model problem...

2007-08-14 Thread [EMAIL PROTECTED]
Thanks for all the help. I ended up using this: View... s = User.objects.all().values('id', 'username', 'first_name', 'last_name',) users = [] for u in s: p = Poem.objects.filter(user=u['id'], approved=True) users.append({ 'id': u['id'],

Re: Filter on related model problem...

2007-08-13 Thread Collin Grady
Regroup generates a list of dicts with two keys - grouper (the value of the field you're grouping by) and list (the list of objects that match that) So in this case, you get entries like {'grouper': , 'list': [, , ...]} :) --~--~-~--~~~---~--~~ You received this

Re: Filter on related model problem...

2007-08-13 Thread [EMAIL PROTECTED]
Nice--I was thinking about using regroup, but I didn't think this was a "proper" use of it. Thanks! On Aug 13, 8:22 pm, Collin Grady <[EMAIL PROTECTED]> wrote: > view: > > poems = > Poem.objects.filter(approved=True).select_related().order_by('auth_user.use > rname') > > template: > > {% regroup

Re: Filter on related model problem...

2007-08-13 Thread Carl Karsten
Collin Grady wrote: > view: > > poems = > Poem.objects.filter(approved=True).select_related().order_by('auth_user.username') > > template: > > {% regroup poems by user as grouped %} > {% for group in grouped %} > {{ group.grouper }} > {% for poem in group.list %} > {{ poem.title }} > {% endfor

Re: Filter on related model problem...

2007-08-13 Thread Collin Grady
view: poems = Poem.objects.filter(approved=True).select_related().order_by('auth_user.username') template: {% regroup poems by user as grouped %} {% for group in grouped %} {{ group.grouper }} {% for poem in group.list %} {{ poem.title }} {% endfor %} {% endfor %} Perhaps something like that?

Re: Filter on related model problem...

2007-08-13 Thread [EMAIL PROTECTED]
> u = User.objects.filter(poem_set__approved=True) I think you meant: u = User.objects.filter(poem__approved=True) > and then in your template, you can have something like > > {% for user in users %} >User: {{ user }} >{% for poem in user.poems %} > {% if poem.approved %} > {

Re: Filter on related model problem...

2007-08-13 Thread Tim Chase
> I have a "poem" model that belongs to "user". The "poem" model an > "approved" attribute. I want to print a list of users and display only > their poems that are approved. > > What do I specify in the Queryset to make this work? > > I want to do something like this: > u = User.objects.filter(p

Filter on related model problem...

2007-08-13 Thread [EMAIL PROTECTED]
I have a "poem" model that belongs to "user". The "poem" model an "approved" attribute. I want to print a list of users and display only their poems that are approved. What do I specify in the Queryset to make this work? I want to do something like this: u = User.objects.filter(poem.approved=Tru