Skip to main content

Attributes for django models in a JQuery inspired syntax.

Project description

… is a django app which aims to provide arbitrary attributes for any model without touching it. The flexibility won is paid with the speed lost, which will become obvious in large scaled applications with dense data.


  • Just copy the attributes folder to your current django project and include ‘attributes’ in your settings.
  • Or install it using sudo easy_install anyit.djattributes and include ‘anyit.djattributes.attributes’.


A javascript / JQuery like notation is implemented and provided by a simple interface class called attr. No capital letter like in usual classnames trying to make it feel like JQuery.

Mind the gap

I am a bit concerned about this being not compliant to django philosophy. Make sure you do not use this for large scale non sparse data stuff. I was just bothered with a tree structure containing arbitrary, path dependent attributes. This is why I did it. If I could have avoided this I had my models more nailed down :)

Type interfaces

# Creates a type. Look at the __doc__ for further info on types and
# how they are represented. By now the internal_types int, float,
# string, text, unicode, class (any pickleable object) and contenttype,
# using a django gereric key, are supported.
attr.create_type(name, description , type)

# Careful! The cascade will destroy any values of the given type.

Carrier interfaces

# returns all attribute objects

# returns a list of attributes for the given owner.

# returns the owners attribute with a given name or None.
attr(owner, name)

# ... set its value or raise if the type is not koscher.
attr(owner, name, value)

# create_attributetype chooses between creating an attributetype
# with the given name, type determined by the given value and the
# description set to the given name if a description is not
# explicitely provided. create_attribute will associate a given
# attribute with a carrier which is not yet attached with an
# attribute type like given or raise a NameError. klass chooses
# to enforce the attribute being attached to a model, even if an
# instance is given. as_attribute will return the attribute, not
# it's value.


Attribute interfaces

# returns the owner of a given attribute

# returns a list of attributes for the attribute type of the given name

# returns a list of attributes for the attribute type of the given name matching the value
attr.find(name, value)

Destructive interfaces

# deletes all attributes

# deletes all attributes having the given type.

# deletes all attributes being attached to the given object or class.

# deletes the attribute named n attached to o, the given object or class.
attr.delete(o=object, n=name)


To get started you might also want to run the ./ test attributes command and have a look at the second half of the file.


The PickledObjectField and their tests (found in the first half of taken from and slightly modified so the __in lookup would work, too. Thanks for the snippet. Later I realized, this one might have worked, too:

Have fun and feel free to contact me if you are having trouble, suggestions, …

Project details

Download files

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

Files for anyit.djattributes, version 0.2.5
Filename, size File type Python version Upload date Hashes
Filename, size anyit.djattributes-0.2.5-py2.6.egg (27.6 kB) File type Egg Python version 2.6 Upload date Hashes View
Filename, size anyit.djattributes-0.2.5.tar.gz (12.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page