<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ko_model(model, field_names=None, data=None):
 """ Given a model, returns the Knockout Model and the Knockout ViewModel. Takes optional field names and data. """


    try:
        if isinstance(model, str):
            modelName = model
        else:
            modelName = model.__class__.__name__

        if field_names:
            fields = field_names
        else:
            fields = get_fields(model)

        if hasattr(model, "comparator"):
            comparator = str(model.comparator())
        else:
            comparator = 'id'

        modelViewString = render_to_string(
            "knockout_modeler/model.js",
            {'modelName': modelName, 'fields': fields, 'data': data, 'comparator': comparator}
        )

        return modelViewString
    except Exception as e:
        logger.exception(e)
        return ''