I have a django model:

class Person(models.Model):
    """" Modelo criado com referencia ao modelo remoto """

    name = models.CharField(max_length=300)
    age = models.PositiveIntegerField()
    born = models.DateField()

I want to group all the people by birthday (group by born date). I'm trying 
to get a dictionary of dictionaries, like this:

{ 
    02-17:[
            {
               name:'Daniel',
               age:22
            },
            {
               name:'Pedro',
               age:23
            },
          ],
    05-24:[
            {
               name:'Juan',
               age:44
            }
          ]}

One option is:

query = Person.objects.all().query
query.group_by = ['born']
for item in QuerySet(query=query, model=Person):
    print item

but it returns a list with all objects ordered by date... no grouped.

Can I do this by django ORM or with sql raw? I will have to do it by myself?

Thanks

http://stackoverflow.com/questions/19161671/group-by-django-list

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e1cf2673-f128-4cf7-81b3-37c3e5de0d90%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to