backend
├── erp
│ ├── blueprint_create_order_and_add_products
│ │ ├── __init__.py
│ │ └── resources
│ │ ├── create_order.py
│ │ ├── __init__.py
│ ├── blueprint_general_query
│ │ ├── __init__.py
│ │ └── resources
│ │ ├── general_query.py
│ │ └── __init__.py
│ ├── common
│ │ ├── __init__.py
│ │ └── models
│ │ ├── brand.py
│ │ ├── productwithspecs.py
│ ├── database_collection
│ │ ├── finance.db
│ │ ├── orders.db
│ │ └── vendors.db
│ └── __init__.py
├── __init__.py
└── run.py
Above is sort of my app structure The models folder have db classes, the problem is that the class in brand module involves (through relationship) and imports the class in productwithspecs module, and there are lots of related db classes. How to import them in a CRUD resource of flask restful without circular imports.
The structure of app.py is:
from erp import app
if __name__ == '__main__':
app.run(debug=True)
the code of erp/ini.py is:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:////tmp/test.db"
db = SQLAlchemy(app)
ma = Marshmallow(app)
from erp.blueprint_create_order_and_add_products import bp as bp1 # api_createorders_addproducts
# REGISTER blueprint apis to app
app.register_blueprint(bp1)
Please let me know how to avoid circular imports, as I will be needing to import db classes into resources folder in blueprints e.g create_order module etc. Thanks