Ticket #7904: use_for_related_fields.diff
File use_for_related_fields.diff, 934 bytes (added by , 16 years ago) |
---|
-
django/db/models/fields/related.py
239 239 params = {'%s__pk' % self.field.rel.field_name: val} 240 240 else: 241 241 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) 243 250 setattr(instance, cache_name, rel_obj) 244 251 return rel_obj 245 252