API Documentation

The API of djeneralize is broken down into five modules:

djeneralize

djeneralize.PATH_SEPERATOR

The seperator used to divide hierarchy in specializations

manager

class djeneralize.manager.SpecializationManager

Customized manager to ensure that any QuerySet that is used always returns specialized model instances rather than generalized model instances.

The manager can either return final_specializations, i.e. the most specialized specialization, or the direct specialization of the general model.

direct()

Set the _final_specialization attribute on a clone of the queryset to ensure only directly descended specializations are considered.

Returns:The cloned queryset
Return type:SpecializedQuerySet
final()

Set the _final_specialization attribute on a clone of the queryset to ensure only terminal specializations are considered.

Returns:The cloned queryset
Return type:SpecializedQuerySet
get_query_set()

Instead of returning a QuerySet, use SpecializedQuerySet instead

Returns:A specialized queryset
Return type:SpecializedQuerySet

models

class djeneralize.models.BaseGeneralizationMeta

The metaclass for BaseGeneralizedModel

class djeneralize.models.BaseGeneralizationModel(*args, **kwargs)

Base model from which all Generalized and Specialized models inherit

get_as_specialization(final_specialization=True)

Get the specialized model instance which corresponds to the general case.

Parameters:final_specialization (bool) – Whether the specialization returned is the most specialized specialization or whether the direct specialization is used
Returns:The specialized model corresponding to the current model
set_default_specialization()

Set the specialization_type of this instance to match that specified by its specialization in the inner class Meta.

specialization_type

Field to store the specialization

djeneralize.models.ensure_specialization_manager(sender, **kwargs)

Ensure that a BaseGeneralizationModel subclass contains a default specialization manager and sets the _default_specialization_manager attribute on the class.

Parameters:sender (django.db.models.base.Model) – The class which emitted the class prepared signal which needs to be checked for the specialization manager

query

class djeneralize.query.SpecializedQuerySet(*args, **kwargs)

A wrapper around QuerySet to ensure specialized models are returned.

direct()

Set the _final_specialization attribute on a clone of this queryset to ensure only directly descended specializations are considered.

Returns:The cloned queryset
Return type:SpecializedQuerySet
final()

Set the _final_specialization attribute on a clone of this queryset to ensure only terminal specializations are considered.

Returns:The cloned queryset
Return type:SpecializedQuerySet
get(*args, **kwargs)

Override get to ensure a specialized model instance is returned.

Returns:A specialized model instance
iterator()

Override the iteration to ensure what’s returned are Specialized Model instances.

utils

Utilities for djeneralize

djeneralize.utils.find_next_path_down(current_path, path_to_reduce, separator)

Manipulate path_to_reduce so that it only contains one more level of detail than current_path.

Parameters:
  • current_path (basestring) – The path used to determine the current level
  • path_to_reduce (basestring) – The path to find the next level down
  • separator (basestring) – The string used to separate the parts of path
Returns:

The path one level deeper than that of current_path

Return type:

unicode

Table Of Contents

Previous topic

Querying specialized models

This Page