Fixed #8248: made help() work on models and improved introspection support.
Descriptors now return themselves when accessed via the class, as per standard Python descriptors like property(). git-svn-id: http://code.djangoproject.com/svn/django/trunk@9550 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
4637a77ff8
commit
5ef0c03ae9
|
@ -175,7 +175,7 @@ class SingleRelatedObjectDescriptor(object):
|
||||||
|
|
||||||
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.related.opts.object_name
|
return self
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return getattr(instance, self.cache_name)
|
return getattr(instance, self.cache_name)
|
||||||
|
@ -223,7 +223,7 @@ class ReverseSingleRelatedObjectDescriptor(object):
|
||||||
|
|
||||||
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
|
return self
|
||||||
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)
|
||||||
|
@ -287,7 +287,7 @@ class ForeignRelatedObjectsDescriptor(object):
|
||||||
|
|
||||||
def __get__(self, instance, instance_type=None):
|
def __get__(self, instance, instance_type=None):
|
||||||
if instance is None:
|
if instance is None:
|
||||||
raise AttributeError, "Manager must be accessed via instance"
|
return self
|
||||||
|
|
||||||
rel_field = self.related.field
|
rel_field = self.related.field
|
||||||
rel_model = self.related.model
|
rel_model = self.related.model
|
||||||
|
@ -500,7 +500,7 @@ class ManyRelatedObjectsDescriptor(object):
|
||||||
|
|
||||||
def __get__(self, instance, instance_type=None):
|
def __get__(self, instance, instance_type=None):
|
||||||
if instance is None:
|
if instance is None:
|
||||||
raise AttributeError, "Manager must be accessed via instance"
|
return self
|
||||||
|
|
||||||
# Dynamically create a class that subclasses the related
|
# Dynamically create a class that subclasses the related
|
||||||
# model's default manager.
|
# model's default manager.
|
||||||
|
@ -545,7 +545,7 @@ class ReverseManyRelatedObjectsDescriptor(object):
|
||||||
|
|
||||||
def __get__(self, instance, instance_type=None):
|
def __get__(self, instance, instance_type=None):
|
||||||
if instance is None:
|
if instance is None:
|
||||||
raise AttributeError, "Manager must be accessed via instance"
|
return self
|
||||||
|
|
||||||
# Dynamically create a class that subclasses the related
|
# Dynamically create a class that subclasses the related
|
||||||
# model's default manager.
|
# model's default manager.
|
||||||
|
|
Loading…
Reference in New Issue