def _check_parent_chain(self, instance, name):
        opts = instance._meta
        f = opts.get_field_by_name(name)[0]
        link_field = opts.get_ancestor_link(f.model)
        if f.primary_key and f != link_field:
            return getattr(instance, link_field.attname)
        return None
Check if the field value can be fetched from a parent field already
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.5/django/db/models/query_utils.py/DeferredAttribute._check_parent_chain