NOTE : this library somehow works, but it is not maintained, unfinished, very inefficient, not packaged properly and not Django-ish ...
Say I have a bookcase, with nice books on it... And I want to create a "bookcase" application with my favorite framework.
That's my model
from django.db import models
class Book (models.Model):
title = models.CharField(max_length=100)
genre = models.CharField(max_length=100)
| || |
I would like to calculate some statistics on my books, for example counting them :
| || philosophy || food || novels |
| A-M || how many ??|| how many ??|| how many ??|
| N-Z || how many ??|| how many ??|| how many ??|
| || But that's such a pain, because I have to count on the whole bookcase !!! |
Book.objects.filter(genre="novels")#etc, etc ...
Even in real life that wouldn't be very practical ...
| || || |
| || What is much more clever is to classify my books into several boxes. So instead of counting on the whole bookcase, I can count on each box !!! |
from cube.models import Cube
genre = Dimension('genre')
first_letter_title = Dimension('title__iregex', sample_space=[r'^[a-n].*', r'^[m-z].*'])
That's actually the aim of django-cube. Here, we defined :
- 2 dimensions (genre and first_letter_title) : they actually define our "boxes"
- the aggregation method : corresponds with the operation to apply on each "box" (count in our case), with queryset corresponding to the base queryset of the "box" !