Ticket #7904: use_for_related_fields.diff

File use_for_related_fields.diff, 934 bytes (added by jbronn, 16 years ago)

Patch that looks for use_for_related_fields attribute on managers.

  • django/db/models/fields/related.py

     
    239239                params = {'%s__pk' % self.field.rel.field_name: val}
    240240            else:
    241241                params = {'%s__exact' % self.field.rel.field_name: val}
    242             rel_obj = QuerySet(self.field.rel.to).get(**params)
     242
     243            # If the related manager indicates that it should be used for
     244            # related fields, respect that.
     245            rel_mgr = self.field.rel.to._default_manager
     246            if getattr(rel_mgr, 'use_for_related_fields', False):
     247                rel_obj = rel_mgr.get(**params)
     248            else:
     249                rel_obj = QuerySet(self.field.rel.to).get(**params)
    243250            setattr(instance, cache_name, rel_obj)
    244251            return rel_obj
    245252
Back to Top