On Jul 15, 10:13 am, Suprnaturall <n.her...@gmail.com> wrote: > Hi dear django users :) > > I m facing a stupid problem. > Here is my models.py : > > class Video(models.Model): > (...) > category = models.ForeignKey('Category') > (...) > > class Category(models.Model): > name = models.CharField(max_length=250) > > I'm trying in a tags to make a group by on the category field and > retrieve in the template the name of the first vid and its category > name. > > Here it s my teamplate.py : > > @register.inclusion_tag('appFront/home_tag.html') > def home_vods(): > videos = > Video.objects.values('category').annotate(dcount=Count('category')) > return {'videos': videos}
Queryset.values(*fieldnames) returns a list of fieldname:value dicts (instead of model instances), possibly restricted to specified fieldnames. https://docs.djangoproject.com/en/1.3/ref/models/querysets/#values > Do you have any clue ? What is the correct way to make a group by and > then retrieve all the data in the table ? I don't see the point of a group_by here. Would you care to explain more exactly what you are trying to achieve (I mean, the desired output - not what you think is the solution). -- 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 django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.