Ticket #7506: related.diff
File related.diff, 2.1 KB (added by , 16 years ago) |
---|
-
related.py
98 98 def contribute_to_class(self, cls, name): 99 99 sup = super(RelatedField, self) 100 100 101 # Add an accessor to allow easy determination of the related query path for this field 102 self.related_query_name = curry(self._get_related_query_name, cls._meta) 101 self._cls_object_name = cls._meta.object_name 103 102 104 103 if hasattr(sup, 'contribute_to_class'): 105 104 sup.contribute_to_class(cls, name) … … 111 110 if not cls._meta.abstract and self.rel.related_name: 112 111 self.rel.related_name = self.rel.related_name % {'class': cls.__name__.lower()} 113 112 113 # Accessor to allow easy determination of the related query path for this field 114 def related_query_name(self): 115 # This method defines the name that can be used to identify this 116 # related object in a table-spanning query. It uses the lower-cased 117 # object_name by default, but this can be overridden with the 118 # "related_name" option. 119 return self.rel.related_name or self._cls_object_name.lower() 120 114 121 def set_attributes_from_rel(self): 115 122 self.name = self.name or (self.rel.to._meta.object_name.lower() + '_' + self.rel.to._meta.pk.name) 116 123 self.verbose_name = self.verbose_name or self.rel.to._meta.verbose_name … … 150 157 return [] 151 158 raise TypeError, "Related Field has invalid lookup: %s" % lookup_type 152 159 153 def _get_related_query_name(self, opts):154 # This method defines the name that can be used to identify this155 # related object in a table-spanning query. It uses the lower-cased156 # object_name by default, but this can be overridden with the157 # "related_name" option.158 return self.rel.related_name or opts.object_name.lower()159 160 160 class SingleRelatedObjectDescriptor(object): 161 161 # This class provides the functionality that makes the related-object 162 162 # managers available as attributes on a model class, for fields that have