I have declared models which requires the use of database relationships in modules of both models leading to a "Cannot import name Region
" error.
To better illustrate this, here is my sample models
project/location/models.py
from project.location.models import Region
class Project(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(175), unique=True, nullable=False)
region = db.Column(db.Integer, db.ForeignKey('regions.id'))
regions = db.relationship(Region, backref='projects')
from the next module,
project/deliverables/models
from project.deliverables.models import Project
class Region(db.Model):
name = db.Column(db.String(30))
id = db.Column(db.Integer, primary_key=True)
projects = db.relationship("Project", backref='regions')
How best can I avoid circular import so future models declaration will not be entangled in this phenomena ?