def _get_related_models(m):
 related_models = [subclass for subclass in m.__subclasses__() if issubclass(subclass, models.Model)]
 related_fields_models = set()
 for f in m._meta.get_fields(include_parents=True, include_hidden=True):
  if (f.is_relation and (f.related_model is not None) and (not isinstance(f.related_model, str))):
   related_fields_models.add(f.model)
   related_models.append(f.related_model)
 opts = m._meta
 if (opts.proxy and (m in related_fields_models)):
  related_models.append(opts.concrete_model)
 return related_models

def _get_related_models ( m ) : related_models = [ subclass for subclass in m . __subclasses__ ( ) if issubclass ( subclass , models . Model ) ] related_fields_models = set ( ) for f in m . _meta . get_fields ( include_parents = True , include_hidden = True ) : if ( f . is_relation and ( f . related_model is not None ) and ( not isinstance ( f . related_model , str ) ) ) : related_fields_models . add ( f . model ) related_models . append ( f . related_model ) opts = m . _meta if ( opts . proxy and ( m in related_fields_models ) ) : related_models . append ( opts . concrete_model ) return related_models
return all models that have a direct relationship to the given model .