Grouping data by field with the Django ORM
I just finished creating some charts for my Django app using Highcharts and had to group some data for them. I thought it would be just as simple as calling a group_by() method but turned out it works a little differently but still pretty straightforward and well documented.
Just to show an example (I’m using Django 1.6):
# glucoses/models.py class Category(models.Model): name = models.CharField(unique=True, max_length=255) class Glucose(TimeStampedModel): user = models.ForeignKey(User) value = models.PositiveIntegerField() # …