You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a models manager, this manager will have all the models and it will be here that it will contain several ready-made functions. As the create_tables method that will create tables regardless of having to create one table before another, it will do this automatically. It will also make it easier to create future features.
Need:
fromdatabasesimportDatabasefromduck_orm.sqlimportfieldsasFieldfromduck_orm.modelimportModel, ManagerModeldb=Database('sqlite:///example.db')
manager=ManagerModel()
awaitdb.connect()
classCity(Model):
__tablename__='cities'__db__=dbmanager=managerid: int=Field.Integer(primary_key=True, auto_increment=True)
name: str=Field.String(unique=True)
defrelationships(self):
self.persons=OneToMany(
model=Person,
name_in_table_fk='city',
name_relation='person_city'
)
classPerson(Model):
__tablename__='persons'__db__=dbmanager=managerid: int=Field.Integer(primary_key=True, auto_increment=True)
first_name: str=Field.String(unique=True)
last_name: str=Field.String(not_null=True)
age: int=Field.BigInteger()
salary: int=Field.BigInteger()
city: City=ForeignKey(model=City, name_in_table_fk='id')
# He will know that he must create the `City` table first.awaitmanager.create_tables()
The text was updated successfully, but these errors were encountered:
Feature description::
Create a models manager, this manager will have all the models and it will be here that it will contain several ready-made functions. As the
create_tables
method that will create tables regardless of having to create one table before another, it will do this automatically. It will also make it easier to create future features.Need:
The text was updated successfully, but these errors were encountered: