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
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
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'],
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
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
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
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?
> 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 %}
> {
> 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
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
10 matches
Mail list logo