|
Project Information
Featured
Links
|
NOTE : this library somehow works, but it is unfinished, very inefficient, not packaged properly, not Django-ish and unmaintained ... mostly by lack of time. Since many people were interested in it, I've started (slowly) development from scratch, with a better design here : https://github.com/sebpiq/django-cube
IntroductionSay 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
class BookCaseCube(Cube):
genre = Dimension('genre')
first_letter_title = Dimension('title__iregex', sample_space=[r'^[a-n].*', r'^[m-z].*'])
@staticmethod
def aggregation(queryset):
return queryset.count()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" !
|
| | |