This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Attach metadata to any Django models using redis.

Installation

Either check out the package from GitHub or it pull from a release via PyPI:

pip install django-metadata

Usage

With django-metadata you can attach metadata to any Django models, you will be able to link keys and theirs values to any instances.

Currently only Redis is supported with only redis-py as backend.

Let’s say you have this model:

# models.py

from django.db import models

class User(models.Model):
    username = models.CharField(max_length=150)

Now you have to attach the MetadataMixin to your model:

# models.py

from django.db import models

from metadata.mixins import MetadataMixin

class User(MetadataMixin, models.Model):
    username = models.CharField(max_length=150)

You can customize the way django-metadata is storing your values by providing a metadata_key property to your model:

# models.py

from django.db import models

from metadata.mixins import MetadataMixin

class User(MetadataMixin, models.Model):
    username = models.CharField(max_length=150)

    def metadata_key(self):
        return 'metadata:utilisateur:%d' % self.pk

By default, the schema will be metadata:%(lowerclassname)s:%(primary_key)s.

Now we have connected our model to the mixin we can play with the API.

The API of MetadataContainer follows the same principes as dict.

Adding keys

>>> from myapp.models import User
>>> user = User.objects.create(username='thoas')
>>> user.metadata['mail_signup_sent'] = 1
>>> user = User.objects.get(username='thoas')
>>> user.metadata['mail_signup_sent']
1
>>> user.metadata = {'mail_signup_sent': 0}
>>> user.metadata['mail_signup_sent']
0

Removing keys

You can either removing a key by setting its value to None or use the del operator.

>>> del user.metadata['key']
>>> user.metadata['key']
Traceback (most recent call last):
    ...
KeyError: 'key'
>>> user.metadata.get('key', None)
None
>>> user.metadata['foo'] = 'bar'
>>> user.metadata['foo'] = None
>>> user.metadata['foo']
Traceback (most recent call last):
    ...
KeyError: 'foo'
>>> user.metadata.get('foo', None)
None
>>> user.metadata['key'] = 'value'
>>> user.metadata['foo'] = 'bar'
>>> user.metadata = {'foo': None}
>>> user.metadata['foo']
Traceback (most recent call last):
    ...
KeyError: 'foo'
>>> user.metadata['key']
value

Iterating keys

>>> 'value' in user.metadata
True
>>> user.metadata.values()
['value']
>>> user.metadata.keys()
['key']
>>> user.metadata.items()
[('key', 'value')]

Incrementing keys

As we are using Redis as storing engine you can use some of its nice features:

>>> user.metadata.incr('counter')
>>> user.metadata['counter']
1
>>> user.metadata.incr('counter', 2)
>>> user.metadata['counter']
3

Inspiration

django-metadata comes from an original idea of twidi.

Release History

Release History

0.2.0

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.1.5

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.4

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.3

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

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-metadata-0.2.0.tar.gz (7.7 kB) Copy SHA256 Checksum SHA256 Source Oct 10, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development 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