Reference

Decorators

denorm.denormalized(DBField, *args, **kwargs)

Turns a callable into model field, analogous to python’s @property decorator. The callable will be used to compute the value of the field every time the model gets saved. If the callable has dependency information attached to it the fields value will also be recomputed if the dependencies require it.

Arguments:

DBField (required)
The type of field you want to use to save the data. Note that you have to use the field class and not an instance of it.
*args, **kwargs:
Those will be passed unaltered into the constructor of DBField once it gets actually created.

Attaches a dependency to a callable, indicating the return value depends on fields in an other model that is related to the model the callable belongs to either through a ForeignKey in either direction or a ManyToManyField.

Arguments:

othermodel (required)
Either a model class or a string naming a model class.
foreign_key
The name of the ForeignKey or ManyToManyField that creates the relation between the two models. Only necessary if there is more than one relationship between the two models.
type
One of ‘forward’, ‘backward’, ‘forward_m2m’ or ‘backward_m2m’. If there are relations in both directions specify which one to use.
skip
Use this to specify what fields change on every save(). These fields will not be checked and will not make a model dirty when they change, to prevent infinite loops.

Fields

class denorm.CacheKeyField(**kwargs)

A BigIntegerField that gets set to a random value anytime the model is saved or a dependency is triggered.

__init__(**kwargs)

All arguments are passed on to the contructor of BigIntegerField.

Add dependency information to the CacheKeyField. Accepts the same arguments like the denorm.depend_on_related decorator

class denorm.CountField(manager_name, **kwargs)

A PositiveIntegerField that stores the number of rows related to this model instance through the specified manager. The value will be incrementally updated when related objects are added and removed.

__init__(manager_name, **kwargs)

Arguments:

manager_name:
The name of the related manager to be counted.

Any additional arguments are passed on to the contructor of PositiveIntegerField.

Functions

denorm.flush()

Updates all model instances marked as dirty by the DirtyInstance model. After this method finishes the DirtyInstance table is empty and all denormalized fields have consistent data.

Middleware

class denorm.middleware.DenormMiddleware

Calls denorm.flush during the response stage of every request. If your data mostly or only changes during requests this should be a good idea. If you run into performance problems with this (because flush() takes to long to complete) you can try using a daemon or handle flushing manually instead.

As usual the order of middleware classes matters. It makes a lot of sense to put DenormMiddleware after TransactionMiddleware in your MIDDLEWARE_CLASSES setting.

Management commands

denorm_init
denorm_rebuild
Recalculates the value of every single denormalized model field in the whole project.
denorm_flush
Recalculates the value of every denormalized field that was marked dirty.
denorm_daemon
Runs a daemon that checks for dirty fields and updates them in regular intervals. The default interval ist one second, this can be overridden by specifying the desired interval as a numeric argument to the command.
denorm_sql
Prints out the SQL used to create all triggers needed to track changes to models that may cause data to become inconsistent.

Table Of Contents

Previous topic

Tutorial

This Page