Ticket #7135: databrowse-fix-for-inheritance.diff

File databrowse-fix-for-inheritance.diff, 1.5 KB (added by Andy MacKinlay, 17 years ago)
  • django/contrib/databrowse/datastructures.py

     
    1010from django.utils.encoding import smart_unicode, smart_str, iri_to_uri
    1111from django.utils.safestring import mark_safe
    1212from django.db.models.query import QuerySet
    13 
     13from django.core.exceptions import ObjectDoesNotExist
     14 
    1415EMPTY_VALUE = '(None)'
    1516DISPLAY_SIZE = 100
    1617
     
    125126            if rel_object.model not in self.model.model_list:
    126127                continue # Skip models that aren't in the model_list
    127128            em = EasyModel(self.model.site, rel_object.model)
     129            try:
     130                rel_accessor = getattr(self.instance, rel_object.get_accessor_name())
     131            except ObjectDoesNotExist:
     132                continue               
     133            if rel_object.field.rel.multiple:
     134                object_list = [EasyInstance(em, i) for i in rel_accessor.all()]
     135            else: # for one-to-one fields
     136                object_list = [EasyInstance(em, rel_accessor)]
    128137            yield {
    129138                'model': em,
    130139                'related_field': rel_object.field.verbose_name,
    131                 'object_list': [EasyInstance(em, i) for i in getattr(self.instance, rel_object.get_accessor_name()).all()],
     140                'object_list': object_list
    132141            }
    133142
    134143class EasyInstanceField(object):
Back to Top