How to split models across multiple files #445
-
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. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
As you mentioned have you tried FutureRef? IT solves those loopholes. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Note that
update_forward_refs
accepts not onlyglobals
, but alsolocals
dictionary that you can pass.So with dummy structure like this:
So you can do something like this:
user.py
image.py