@@ -119,7 +119,6 @@ def generate_model(
119119 ** kwargs ,
120120 ) -> str :
121121 """method to prepare one Model defention - name & tablename & columns"""
122- model = ""
123122
124123 model = st .model_template .format (
125124 model_name = create_class_name (table .name , singular , exceptions ),
@@ -133,26 +132,31 @@ def generate_model(
133132 col_str = st .column_template .format (
134133 column_name = column .name .replace (" " , "_" ), column_type = pydantic_type_str
135134 )
136-
137- col_str = logic .setup_column_attributes (
138- column , table .primary_key , col_str , table , schema_global , st , self
135+ attrs_col_str = logic .setup_column_attributes (
136+ column , table .primary_key , "" , table , schema_global , st , self
139137 )
140138 if column_type ["sa" ]:
141139 sa_type = types .add_size_to_orm_column (column_type ["sa" ], column )
142- col_str += st .sa_type .format (satype = sa_type )
143- col_str += ") \n "
144-
145- col_str = col_str . replace ( "(, " , "(" )
146-
140+ attrs_col_str += st .sa_type .format (satype = sa_type )
141+ if attrs_col_str :
142+ attrs_col_str = attrs_col_str . replace ( "," , "" , 1 ). strip ()
143+ col_str += st . field_template . format ( attr_data = attrs_col_str )
144+ col_str += " \n "
147145 model += col_str
148146 if table .indexes or table .alter or table .checks or not schema_global :
149147 model = self .add_table_args (model , table , schema_global )
150148 return model
151149
152- def create_header (self , tables : List [Dict ], schema : bool = False ) -> str :
150+ def create_header (
151+ self ,
152+ tables : List [Dict ],
153+ models_str : str ,
154+ schema : bool = False ,
155+ ) -> str :
153156 """header of the file - imports & sqlalchemy init"""
154157 header = ""
155- header += st .sqlalchemy_import # Do we always need this import?
158+ if "sa." in models_str :
159+ header += st .sqlalchemy_import # Do we always need this import?
156160 if "func" in self .state :
157161 header += st .sql_alchemy_func_import + "\n "
158162 if self .postgresql_dialect_cols :
0 commit comments