Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

magic-removal: Fixed #1159 -- Fixed error in 'unique' manipulator val…

…idator

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1828 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 1885443c8239e09b06330096e15704c0d2779a87 1 parent 9033ba7
@adrianholovaty adrianholovaty authored
View
6 django/db/models/fields/__init__.py
@@ -36,7 +36,7 @@ def manipulator_validator_unique(f, opts, self, field_data, all_data):
"Validates that the value is unique for this field."
lookup_type = f.get_validator_unique_lookup_type()
try:
- old_obj = self.__class__._default_manager.get_object(**{lookup_type: field_data})
+ old_obj = self.manager.get_object(**{lookup_type: field_data})
except ObjectDoesNotExist:
return
if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.attname) == getattr(old_obj, opts.pk.attname):
@@ -216,13 +216,13 @@ def prepare_field_objs_and_params(self, manipulator, name_prefix):
params['choices'] = self.get_choices_default()
else:
field_objs = self.get_manipulator_field_objs()
- return (field_objs,params)
+ return (field_objs, params)
def get_fields_and_manipulators(self, opts, manipulator, follow):
change = manipulator.change
rel = manipulator.name_prefix != ''
name_prefix = manipulator.name_prefix
- return (self.get_manipulator_fields(opts, manipulator, change,name_prefix, rel, follow), None )
+ return (self.get_manipulator_fields(opts, manipulator, change, name_prefix, rel, follow), None)
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False, follow=True):
"""
View
19 django/db/models/manipulators.py
@@ -80,7 +80,7 @@ def contribute_to_class(cls, other_cls, name):
setattr(other_cls, name, ManipulatorDescriptor(name, cls))
contribute_to_class = classmethod(contribute_to_class)
- def __init__(self, original_object=None, follow=None, name_parts=() ):
+ def __init__(self, original_object=None, follow=None, name_parts=()):
Naming.__init__(self, name_parts)
if name_parts == ():
self.follow = self.model._meta.get_follow(follow)
@@ -100,7 +100,7 @@ def __init__(self, original_object=None, follow=None, name_parts=() ):
self.ignore_errors = False
def get_fields(self):
- if self.needs_deletion :
+ if self.needs_deletion:
return []
else:
return self.fields_
@@ -130,7 +130,7 @@ def do_html2python(self, new_data):
child.do_html2python(new_data)
def get_original_value(self, field):
- raise NotImplemented
+ raise NotImplementedError
def get_new_object(self, expanded_data, overrides=None):
params = {}
@@ -200,11 +200,10 @@ def _do_command_expanded(self, command_parts):
child_manips = manips
break
if child_manips == None:
- raise BadCommand, "'%s' : unknown manipulator collection name." % (part,)
+ raise BadCommand, "'%s': unknown manipulator collection name." % (part,)
else:
child_manips._do_command_expanded(command_parts)
-
def save(self, new_data):
self.update(new_data)
self.save_from_update()
@@ -285,7 +284,7 @@ def get_original_value(self, field):
return field.get_default()
def __repr__(self):
- return "<Automatic AddManipulator '%s' for %s>" % (self.name_prefix, self.model.__name__, )
+ return "<Automatic AddManipulator '%s' for %s>" % (self.name_prefix, self.model.__name__)
class ModelChangeManipulator(AutomaticManipulator):
change = True
@@ -318,6 +317,10 @@ def __init__(self, obj_key=None, follow=None, name_parts=()):
original_object = opts.get_model_module().Klass(**params)
else:
raise
+ else:
+ # Save the obj_key even though we already have it, in case it's
+ # currently a string and needs to be an integer.
+ self.obj_key = getattr(original_object, self.model._meta.pk.attname)
super(ModelChangeManipulator, self).__init__(original_object=original_object, follow=follow, name_parts=name_parts)
#self.original_object = original_object
@@ -347,7 +350,7 @@ def _load(self):
man_class = self.model.ChangeManipulator
for i,obj in enumerate(self._get_list()):
- self.append(man_class(obj,self.follow, self.name_parts + (str(i),) ))
+ self.append(man_class(obj, self.follow, self.name_parts + (str(i),)))
def _save_child(self, manip, parent_key):
manip.save_from_update()
@@ -370,7 +373,7 @@ def _fill_data(self, expanded_data):
manip.needs_deletion = True
if expanded_data:
# There are new objects in the data
- items = [ (int(k),v ) for k,v in expanded_data.items() ]
+ items = [(int(k), v) for k, v in expanded_data.items()]
items.sort(cmp = lambda x, y: cmp(x[0], y[0]))
for index, obj_data in items:
child_manip = self.add_child(index)
Please sign in to comment.
Something went wrong with that request. Please try again.