def get_limit_choices_to_from_path(model, path):
 fields = get_fields_from_path(model, path)
 fields = remove_trailing_data_field(fields)
 limit_choices_to = (fields and hasattr(fields[(-1)], 'rel') and getattr(fields[(-1)].rel, 'limit_choices_to', None))
 if (not limit_choices_to):
  return models.Q()
 elif isinstance(limit_choices_to, models.Q):
  return limit_choices_to
 else:
  return models.Q(**limit_choices_to)

def get_limit_choices_to_from_path ( model , path ) : fields = get_fields_from_path ( model , path ) fields = remove_trailing_data_field ( fields ) limit_choices_to = ( fields and hasattr ( fields [ ( - 1 ) ] , 'rel' ) and getattr ( fields [ ( - 1 ) ] . rel , 'limit_choices_to' , None ) ) if ( not limit_choices_to ) : return models . Q ( ) elif isinstance ( limit_choices_to , models . Q ) : return limit_choices_to else : return models . Q ( ** limit_choices_to )
return q object for limiting choices if applicable .