Repository navigation
How to split models across multiple files #445
Answered
by
collerek
michaeltoohig
asked this question in
Q&A
|
How to avoid circular imports when splitting models into multiple files? I didn't see in docs how to use a string representation of a model for a ForeignKey or a type annotation. I did see FutureRef but that still requires importing the FutureRef from the other file and creates the same circular import. This would be possible with SQLAlchemy or Marshmallow libraries for an example. I would like to avoid a models.py file from becoming a huge behemoth if possible. |
Answered by
collerek
Dec 6, 2021
Replies: 2 comments 3 replies
|
As you mentioned have you tried FutureRef? IT solves those loopholes. |
2 replies
1 reply
Answer selected by
michaeltoohig
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Note that
update_forward_refsaccepts not onlyglobals, but alsolocalsdictionary that you can pass.So with dummy structure like this:
So you can do something like this:
user.py
image.py