def get_object_usage(obj):
 pages = Page.objects.none()
 relations = [f for f in type(obj)._meta.get_fields(include_hidden=True) if ((f.one_to_many or f.one_to_one) and f.auto_created)]
 for relation in relations:
  related_model = relation.related_model
  if issubclass(related_model, Page):
   pages |= Page.objects.filter(id__in=related_model._base_manager.filter(**{relation.field.name: obj.id}).values_list(u'id', flat=True))
  else:
   for f in related_model._meta.fields:
    if (isinstance(f, ParentalKey) and issubclass(f.rel.to, Page)):
     pages |= Page.objects.filter(id__in=related_model._base_manager.filter(**{relation.field.name: obj.id}).values_list(f.attname, flat=True))
 return pages

def get_object_usage ( obj ) : pages = Page . objects . none ( ) relations = [ f for f in type ( obj ) . _meta . get_fields ( include_hidden = True ) if ( ( f . one_to_many or f . one_to_one ) and f . auto_created ) ] for relation in relations : related_model = relation . related_model if issubclass ( related_model , Page ) : pages |= Page . objects . filter ( id__in = related_model . _base_manager . filter ( ** { relation . field . name : obj . id } ) . values_list ( u'id' , flat = True ) ) else : for f in related_model . _meta . fields : if ( isinstance ( f , ParentalKey ) and issubclass ( f . rel . to , Page ) ) : pages |= Page . objects . filter ( id__in = related_model . _base_manager . filter ( ** { relation . field . name : obj . id } ) . values_list ( f . attname , flat = True ) ) return pages
returns a queryset of pages that link to a particular object .