Fixed bug for OneToOneFields in the admin -- the manipulator_validator_unique wasn't doing the correct lookup
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1322 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
b96f6059f0
commit
7a80b2cc98
|
@ -79,13 +79,6 @@ def change_list(request, app_label, module_name):
|
||||||
|
|
||||||
lookup_mod, lookup_opts = mod, opts
|
lookup_mod, lookup_opts = mod, opts
|
||||||
|
|
||||||
if opts.one_to_one_field:
|
|
||||||
lookup_mod = opts.one_to_one_field.rel.to.get_model_module()
|
|
||||||
lookup_opts = lookup_mod.Klass._meta
|
|
||||||
# If lookup_opts doesn't have admin set, give it the default meta.Admin().
|
|
||||||
if not lookup_opts.admin:
|
|
||||||
lookup_opts.admin = meta.Admin()
|
|
||||||
|
|
||||||
# Get search parameters from the query string.
|
# Get search parameters from the query string.
|
||||||
try:
|
try:
|
||||||
page_num = int(request.GET.get(PAGE_VAR, 0))
|
page_num = int(request.GET.get(PAGE_VAR, 0))
|
||||||
|
|
|
@ -48,11 +48,11 @@ def manipulator_valid_rel_key(f, self, field_data, all_data):
|
||||||
def manipulator_validator_unique(f, opts, self, field_data, all_data):
|
def manipulator_validator_unique(f, opts, self, field_data, all_data):
|
||||||
"Validates that the value is unique for this field."
|
"Validates that the value is unique for this field."
|
||||||
if f.rel and isinstance(f.rel, ManyToOne):
|
if f.rel and isinstance(f.rel, ManyToOne):
|
||||||
lookup_type = 'pk'
|
lookup_type = '%s__%s__exact' % (f.name, f.rel.get_related_field().name)
|
||||||
else:
|
else:
|
||||||
lookup_type = 'exact'
|
lookup_type = '%s__exact' % (f.name, lookup_type)
|
||||||
try:
|
try:
|
||||||
old_obj = opts.get_model_module().get_object(**{'%s__%s' % (f.name, lookup_type): field_data})
|
old_obj = opts.get_model_module().get_object(**{lookup_type: field_data})
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
return
|
return
|
||||||
if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.attname) == getattr(old_obj, opts.pk.attname):
|
if hasattr(self, 'original_object') and getattr(self.original_object, opts.pk.attname) == getattr(old_obj, opts.pk.attname):
|
||||||
|
|
Loading…
Reference in New Issue