Skip to content
This repository has been archived by the owner on Jul 20, 2018. It is now read-only.

Commit

Permalink
Make model key configurable via the model's Meta class.
Browse files Browse the repository at this point in the history
  • Loading branch information
iamteem committed Jun 17, 2010
1 parent 6f65bde commit 79675d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions redisco/models/base.py
Expand Up @@ -86,7 +86,7 @@ def _initialize_counters(model_class, name, bases, attrs):

def _initialize_key(model_class, name):
"""Initializes the key of the model."""
model_class._key = Key(name)
model_class._key = Key(model_class._meta['key'] or name)


def _initialize_manager(model_class):
Expand Down Expand Up @@ -168,7 +168,7 @@ def is_valid(self):

def validate(self):
"""Overriden in the model class.
Do custom validation here. Add tuples to self._errors.
Example:
Expand Down
16 changes: 15 additions & 1 deletion tests/models.py
Expand Up @@ -212,7 +212,7 @@ def test_exclude(self):
.exclude(last_name="Mommy"))
self.assertEqual(3, len(persons))


def test_first(self):
Person.objects.create(first_name="Granny", last_name="Goose")
Person.objects.create(first_name="Clark", last_name="Kent")
Expand Down Expand Up @@ -501,6 +501,20 @@ def test_get_or_create(self):
self.assertEqual('7', p.id)


def test_customizable_key(self):
class Person(models.Model):
name = models.CharField()

class Meta:
key = 'People'

p = Person(name="Clark Kent")
self.assert_(p.is_valid())
self.assert_(p.save())

self.assert_('1' in self.client.smembers('People:all'))


class Event(models.Model):
name = models.CharField(required=True)
date = models.DateField(required=True)
Expand Down

0 comments on commit 79675d2

Please sign in to comment.