mirror of
https://github.com/django/django.git
synced 2025-06-16 00:49:12 +00:00
magic-removal: Changed SingleRelatedObjectDescriptor to use self._field instead of self.field
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2209 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ac67992c79
commit
5bf57ef71c
@ -69,25 +69,25 @@ class SingleRelatedObjectDescriptor(object):
|
|||||||
# In the example "choice.poll", the poll attribute is a
|
# In the example "choice.poll", the poll attribute is a
|
||||||
# SingleRelatedObjectDescriptor instance.
|
# SingleRelatedObjectDescriptor instance.
|
||||||
def __init__(self, field_with_rel):
|
def __init__(self, field_with_rel):
|
||||||
self.field = field_with_rel
|
self._field = field_with_rel
|
||||||
|
|
||||||
def __get__(self, instance, instance_type=None):
|
def __get__(self, instance, instance_type=None):
|
||||||
if instance is None:
|
if instance is None:
|
||||||
raise AttributeError, "%s must be accessed via instance" % self.field.name
|
raise AttributeError, "%s must be accessed via instance" % self._field.name
|
||||||
else:
|
else:
|
||||||
cache_name = self.field.get_cache_name()
|
cache_name = self._field.get_cache_name()
|
||||||
try:
|
try:
|
||||||
return getattr(instance, cache_name)
|
return getattr(instance, cache_name)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
val = getattr(instance, self.field.attname)
|
val = getattr(instance, self._field.attname)
|
||||||
if val is None:
|
if val is None:
|
||||||
raise self.field.rel.to.DoesNotExist
|
raise self._field.rel.to.DoesNotExist
|
||||||
other_field = self.field.rel.get_related_field()
|
other_field = self._field.rel.get_related_field()
|
||||||
if other_field.rel:
|
if other_field.rel:
|
||||||
params = {'%s__%s__exact' % (self.field.rel.field_name, other_field.rel.field_name): val}
|
params = {'%s__%s__exact' % (self._field.rel.field_name, other_field.rel.field_name): val}
|
||||||
else:
|
else:
|
||||||
params = {'%s__exact' % self.field.rel.field_name: val}
|
params = {'%s__exact' % self._field.rel.field_name: val}
|
||||||
rel_obj = self.field.rel.to._default_manager.get(**params)
|
rel_obj = self._field.rel.to._default_manager.get(**params)
|
||||||
setattr(instance, cache_name, rel_obj)
|
setattr(instance, cache_name, rel_obj)
|
||||||
return rel_obj
|
return rel_obj
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user