Skip to content

Commit

Permalink
Fixes issue #22
Browse files Browse the repository at this point in the history
  • Loading branch information
kiddouk committed Mar 13, 2012
1 parent e8b21cb commit 856d2c1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions redisco/models/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from datetime import datetime, date
from dateutil.tz import tzutc, tzlocal
from redisco.containers import List
from exceptions import FieldValidationError
from exceptions import FieldValidationError, MissingID

__all__ = ['Attribute', 'CharField', 'ListField', 'DateTimeField',
'DateField', 'ReferenceField', 'IntegerField',
Expand Down Expand Up @@ -106,9 +106,15 @@ def validate(self, instance):

def validate_uniqueness(self, instance, val):
encoded = self.typecast_for_storage(val)
same = len(instance.__class__.objects.filter(**{self.name: encoded}))
if same > 0:
return (self.name, 'not unique',)
matches = instance.__class__.objects.filter(**{self.name: encoded})
if len(matches) > 0:
try:
instance_id = instance.id
no_id = False
except MissingID:
no_id = True
if (len(matches) != 1) or no_id or (matches.first().id != instance.id):
return (self.name, 'not unique',)


class CharField(Attribute):
Expand Down

0 comments on commit 856d2c1

Please sign in to comment.