docstr: Creates a new model and trains it
docstr_tok: ["Creates","a","new","model","and","trains","it"]
code: def post(self, project_name):
      """Creates a new model and trains it"""
      session = SessionController()
  
      if "query" not in request.json:
          return http_error(
              HTTPStatus.BAD_REQUEST,
              "Query required",
              'Missing "query" SQL statement',
          )
      query = request.json["query"]
  
      project_datanode = session.datahub.get(project_name)
      if project_datanode is None:
          return http_error(
              HTTPStatus.NOT_FOUND,
              "Project not found",
              f"Project name {project_name} does not exist",
          )
  
      try:
          create_statement = parse_sql(query, dialect="mindsdb")
      except Exception:
          return http_error(
              HTTPStatus.BAD_REQUEST,
              "Invalid query string",
              f"SQL CREATE statement is invalid: {query}",
          )
  
      if type(create_statement) != CreatePredictor:
          return http_error(
              HTTPStatus.BAD_REQUEST,
              "Invalid CREATE SQL statement",
              f"SQL statement is not a CREATE model statement: {query}",
          )
  
      model_name = create_statement.name.parts[1].lower()
      try:
          session.model_controller.get_model(
              model_name, project_name=project_name
          )
          return http_error(
              HTTPStatus.CONFLICT,
              "Model already exists",
              f"Model with name {model_name} already exists",
          )
      except PredictorRecordNotFound:
          pass
  
      ml_integration = "lightwood"
      if create_statement.using is not None:
          # Convert using to lowercase
          create_statement.using = {
              k.lower(): v for k, v in create_statement.using.items()
          }
          ml_integration = create_statement.using.pop(
              "engine", ml_integration
          )
  
      try:
          ml_handler = session.integration_controller.get_handler(
              ml_integration
          )
      except Exception:
          return http_error(
              HTTPStatus.NOT_FOUND,
              "ML handler not found",
              f"Cannot find ML handler with name {ml_integration}",
          )
  
      try:
          model_df = session.model_controller.create_model(
              create_statement, ml_handler
          )
          # Consistent format with GET /projects/<project_name>/models/<model_name>
          return {
              "name": model_df.at[0, "NAME"],
              "accuracy": None,
              "active": model_df.at[0, "ACTIVE"],
              "version": model_df.at[0, "VERSION"],
              "status": model_df.at[0, "STATUS"],
              "predict": model_df.at[0, "PREDICT"],
              "mindsdb_version": model_df.at[0, "MINDSDB_VERSION"],
              "error": model_df.at[0, "ERROR"],
              "fetch_data_query": model_df.at[0, "SELECT_DATA_QUERY"],
              "problem_definition": model_df.at[0, "TRAINING_OPTIONS"],
          }, HTTPStatus.CREATED
      except Exception as e:
          return http_error(
              HTTPStatus.INTERNAL_SERVER_ERROR,
              "Unable to train model",
              f"Something went wrong while creating and training model {model_name}: {e}",
          )
  
imports: from http import HTTPStatus
  import json
  from flask import request
  from flask_restx import Resource
  from sqlalchemy.exc import NoResultFound
  from mindsdb.api.http.namespaces.configs.projects import ns_conf
  from mindsdb.api.http.utils import http_error
  from mindsdb.api.executor.controllers.session_controller import SessionController
  from mindsdb.interfaces.model.functions import PredictorRecordNotFound
  from mindsdb.interfaces.storage.db import Predictor
  from mindsdb_sql import parse_sql
  from mindsdb_sql.parser.dialects.mindsdb import CreatePredictor
label_desc: Use image node_id 2 for calling the ModelsList obj's underlying member method code with example usage: obj.post(project_name) and returns: http_error, http_error, http_error, http_error, dict,  HTTPStatus, http_error, http_error, http_error