<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def after_model_change(self, form, model, is_created):
 """Save model."""

        super(KnowledgeAdmin, self).after_model_change(form, model, is_created)
        from invenio_collections.models import Collection

        if form.kbtype.data == KnwKB.KNWKB_TYPES['dynamic']:
            id_collection = form.id_collection.data or None
            collection = Collection.query.filter_by(
                id=id_collection).one() if id_collection else None

            model.set_dyn_config(
                field=form.output_tag.data,
                expression=form.search_expression.data,
                collection=collection)

        if form.kbtype.data == KnwKB.KNWKB_TYPES['taxonomy']:
            if form.tfile.data:
                file_name = model.get_filename()
                file_data = request.files[form.tfile.name].read()

                with open(file_name, 'w') as f:
                    f.write(file_data)