def get_true_false_both(query_params, field_name, default):
    '''Tries to get and return a valid of true, false, or both from the field
    name in the query string, raises a ValidationError for invalid values.'''
    valid = ('true', 'false', 'both')
    value = query_params.get(field_name, default).lower()
    if value in valid:
        return value
    v = ', '.join(sorted(valid))
    raise serializers.ValidationError({
        field_name: ['Must be one of [%s]' % v],
    })