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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Clay Gerrard authored and iamteem committed Jul 31, 2010
1 parent 83f8f92 commit 27d64e0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
11 changes: 7 additions & 4 deletions redisco/models/attributes.py
Expand Up @@ -339,17 +339,20 @@ def __set__(self, instance, value):
if not isinstance(value, self.value_type()) and \
value is not None:
raise TypeError
# remove the cached value from the instance
if hasattr(instance, '_' + self.name):
delattr(instance, '_' + self.name)
setattr(instance, self.attname, value.id)

def __get__(self, instance, owner):
try:
if not hasattr(self, '_' + self.name):
if not hasattr(instance, '_' + self.name):
o = self.value_type().objects.get_by_id(
getattr(instance, self.attname))
setattr(self, '_' + self.name, o)
return getattr(self, '_' + self.name)
setattr(instance, '_' + self.name, o)
return getattr(instance, '_' + self.name)
except AttributeError:
setattr(self, '_' + self.name, self.default)
setattr(instance, '_' + self.name, self.default)
return self.default

def value_type(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
import os

version = '0.1.0'
version = '0.1.1'

try:
from setuptools import setup
Expand Down
5 changes: 4 additions & 1 deletion tests/models.py
Expand Up @@ -769,7 +769,10 @@ class Character(models.Model):
Character.objects.create(n=34, m='c', word=word)
Character.objects.create(n=34, m='d')
for char in Character.objects.all():
self.assertEqual(word, char.word)
if char.m != 'd':
self.assertEqual(word, char.word)
else:
self.assertEqual(None, char.word)
a, b, c, d = list(Character.objects.all())
self.assertTrue(a in word.character_set)
self.assertTrue(b in word.character_set)
Expand Down

0 comments on commit 27d64e0

Please sign in to comment.