Ticket #17814: concept.patch

File concept.patch, 1.9 KB (added by yanchenko.igor@…, 3 years ago)
  • db/models/related.py

     
    11from django.utils.encoding import smart_unicode
    22from django.db.models.fields import BLANK_CHOICE_DASH
     3from django.conf import settings
    34
    45class BoundRelatedObject(object):
    56    def __init__(self, related_object, field_mapping, original):
     
    5758        # accessor descriptor that retrieves related many-to-one or
    5859        # many-to-many objects. It uses the lower-cased object_name + "_set",
    5960        # but this can be overridden with the "related_name" option.
     61        related_name_override = settings.RELATED_NAME_OVERRIDES.get('%s.%s.%s' % (self.opts.app_label, self.opts.module_name, self.field.name), None)
    6062        if self.field.rel.multiple:
    6163            # If this is a symmetrical m2m relation on self, there is no reverse accessor.
    6264            if getattr(self.field.rel, 'symmetrical', False) and self.model == self.parent_model:
    6365                return None
    64             return self.field.rel.related_name or (self.opts.object_name.lower() + '_set')
     66            return related_name_override or self.field.rel.related_name or (self.opts.object_name.lower() + '_set')
    6567        else:
    66             return self.field.rel.related_name or (self.opts.object_name.lower())
     68            return related_name_override or self.field.rel.related_name or (self.opts.object_name.lower())
    6769
    6870    def get_cache_name(self):
    6971        return "_%s_cache" % self.get_accessor_name()
  • conf/global_settings.py

     
    235235
    236236ABSOLUTE_URL_OVERRIDES = {}
    237237
     238RELATED_NAME_OVERRIDES = {}
     239
    238240# Tuple of strings representing allowed prefixes for the {% ssi %} tag.
    239241# Example: ('/home/html', '/var/www')
    240242ALLOWED_INCLUDE_ROOTS = ()
Back to Top