Skip to content
An identify mapper for the Django ORM
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


This fork of django-idmapper fixes some bugs that prevented the idmapper from being used in many instances. In particular, the caching manager is now inherited by SharedMemoryManager subclasses, and it is used when Django uses an automatic manager (see This means access through foreign keys now uses identity mapping.

Tested with Django version 1.2 alpha 1 SVN-12375.

My modifications are usually accompanied by comments marked with "CL:".

Django Identity Mapper

A pluggable Django application which allows you to explicitally mark your models to use an identity mapping pattern. This will share instances of the same model in memory throughout your interpreter.

Please note, that deserialization (such as from the cache) will not use the identity mapper.


To use the shared memory model you simply need to inherit from it (instead of models.Model). This enable all queries (and relational queries) to this model to use the shared memory instance cache, effectively creating a single instance for each unique row (based on primary key) in the queryset.

For example, if you want to simply mark all of your models as a SharedMemoryModel, you might as well just import it as models.

from idmapper import models

class MyModel(models.SharedMemoryModel):
    name = models.CharField(...)

Because the system is isolated, you may mix and match SharedMemoryModels with regular Models. The module idmapper.models imports everything from django.db.models and only adds SharedMemoryModel, so you can simply replace your import of models from django.db.

from idmapper import models

class MyModel(models.SharedMemoryModel):
    name = models.CharField(...)
    fkey = models.ForeignKey('Other')

class Other(models.Model):
    name = models.CharField(...)


Original code and concept:

You can’t perform that action at this time.