Skip to content

Commit

Permalink
Fixed issue iamteem#20 (incorrectly determining that model attribute …
Browse files Browse the repository at this point in the history
…isn't unique)
  • Loading branch information
jakepic1 committed Oct 5, 2011
1 parent b35f0e4 commit b362fca
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions redisco/models/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time
from datetime import datetime, date
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 @@ -105,9 +105,16 @@ 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 b362fca

Please sign in to comment.