'Returns True if the model associated with this admin should be
allowed to be referenced by the specified field.'

def to_field_allowed(self, request, to_field):

    opts = self.model._meta
    try:
        field = opts.get_field(to_field)
    except FieldDoesNotExist:
        return False
    if field.primary_key:
        return True
    registered_models = set()
    for (model, admin) in self.admin_site._registry.items():
        registered_models.add(model)
        for inline in admin.inlines:
            registered_models.add(inline.model)
    for related_object in opts.get_all_related_objects(include_hidden=True):
        related_model = related_object.model
        if (any((issubclass(model, related_model) for model in registered_models)) and (related_object.field.rel.get_related_field() == field)):
            return True
    return False
