Ticket #6913: databrowse-fix-for-one-to-one.patch

File databrowse-fix-for-one-to-one.patch, 1.3 KB (added by Shaun Cutts, 16 years ago)

proposed patch

  • datastructures.py

     
    121121        EasyInstance's model as a ForeignKey or ManyToManyField, along with
    122122        lists of related objects.
    123123        """
     124        def get_rel_list( instance, rel_object ):
     125            attr = rel_object.get_accessor_name()
     126            if rel_object.field.rel.multiple:
     127                return getattr(instance, attr ).all()
     128            else:
     129                return [ getattr( instance, attr ) ]
     130           
    124131        for rel_object in self.model.model._meta.get_all_related_objects() + self.model.model._meta.get_all_related_many_to_many_objects():
    125132            if rel_object.model not in self.model.model_list:
    126133                continue # Skip models that aren't in the model_list
     
    128135            yield {
    129136                'model': em,
    130137                '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()],
     138                'object_list': [EasyInstance(em, i) for i in get_rel_list( self.instance, rel_object ) ]
    132139            }
    133140
    134141class EasyInstanceField(object):
Back to Top