Ticket #7506: related.diff

File related.diff, 2.1 KB (added by mmalone, 7 years ago)

Patch to remove curry function from RelatedField init

  • related.py

     
    9898    def contribute_to_class(self, cls, name):
    9999        sup = super(RelatedField, self)
    100100
    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
    103102
    104103        if hasattr(sup, 'contribute_to_class'):
    105104            sup.contribute_to_class(cls, name)
     
    111110        if not cls._meta.abstract and self.rel.related_name:
    112111            self.rel.related_name = self.rel.related_name % {'class': cls.__name__.lower()}
    113112
     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
    114121    def set_attributes_from_rel(self):
    115122        self.name = self.name or (self.rel.to._meta.object_name.lower() + '_' + self.rel.to._meta.pk.name)
    116123        self.verbose_name = self.verbose_name or self.rel.to._meta.verbose_name
     
    150157            return []
    151158        raise TypeError, "Related Field has invalid lookup: %s" % lookup_type
    152159
    153     def _get_related_query_name(self, opts):
    154         # This method defines the name that can be used to identify this
    155         # related object in a table-spanning query. It uses the lower-cased
    156         # object_name by default, but this can be overridden with the
    157         # "related_name" option.
    158         return self.rel.related_name or opts.object_name.lower()
    159 
    160160class SingleRelatedObjectDescriptor(object):
    161161    # This class provides the functionality that makes the related-object
    162162    # managers available as attributes on a model class, for fields that have
Back to Top