This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!
Project Description

Materialized Annotations for Django Models. Typical use-case is to keep track of the number of comments in a post, or the number of contributions a user has made.

Installation

pip install dj_mano

Usage

In-code

Using dj_mano is pretty straightforward, you just create a field and give it the annotation you want it to hold.

If you want, you can apply some filter to the annotation you’re doing, like to count only positive reviews by example. In this case, you can provide a function that will return the queryset that will be annotated. Beware, the queryset must be “starting” from the object holding the materialized annotation field.

Models

from django.db import models
from dj_mano import MaterializedAnnotationIntegerField


def swag_model_c():
    return ModelA.objects.filter(models_b__models_c__has_swag=True)


class ModelA(models.Model):
    count_b = MaterializedAnnotationIntegerField(models.Count('models_b'))
    count_c = MaterializedAnnotationIntegerField(models.Count('models_b__models_c'))
    count_swag = MaterializedAnnotationIntegerField(
        models.Count('models_b__models_c'),
        swag_model_c
    )


class ModelB(models.Model):
    model_a = models.ForeignKey('ModelA', related_name='models_b')


class ModelC(models.Model):
    model_b = models.ForeignKey('ModelB', related_name='models_c')
    has_swag = models.BooleanField(default=False)

urls.py

from django.conf.urls import patterns
from dj_mano import hook_it_all

hook_it_all()

urlpatterns = patterns('',
    ...
)

Command

There is a command that will simply synchronize all fields to their actual value.

Note: if you want to use this command, you have to put dj_mano in your INSTALLED_APPS.

./manage.py dj_mano_sync

Licence

This library is licensed under the terms of the WTFPL. Please see the attached LICENSE file.

Release History

Release History

0.2.1

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.1.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
dj_mano-0.2.1.tar.gz (5.1 kB) Copy SHA256 Checksum SHA256 Source Feb 8, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting