Use a dictionary of synonyms and fuzzy string matching to find a similarly named field

    Returns:
      A single model field name (string)

    Examples:

      >>> find_synonymous_field('date', model='WikiItem')
      'end_date_time'
      >>> find_synonymous_field('date', model='WikiItem')
      'date_time'
      >>> find_synonymous_field('time', model='WikiItem')
      'date_time'

def find_synonymous_field(field, model=DEFAULT_MODEL, app=DEFAULT_APP, score_cutoff=50, root_preference=1.02):
    """Use a dictionary of synonyms and fuzzy string matching to find a similarly named field

    Returns:
      A single model field name (string)

    Examples:

      >>> find_synonymous_field('date', model='WikiItem')
      'end_date_time'
      >>> find_synonymous_field('date', model='WikiItem')
      'date_time'
      >>> find_synonymous_field('time', model='WikiItem')
      'date_time'

    """
    fields = util.listify(field) + list(synonyms(field))
    model = get_model(model, app)
    available_field_names = model._meta.get_all_field_names()
    best_match, best_ratio = None, None
    for i, field_name in enumerate(fields):
        match = fuzzy.extractOne(str(field_name), available_field_names)
        # print match
        if match and match[1] >= score_cutoff:
            if not best_match or match[1] > (root_preference * best_ratio):
                best_match, best_ratio = match
    return best_match