Skip to content

How to split models across multiple files #445

Answered by collerek
michaeltoohig asked this question in Q&A
Discussion options

You must be logged in to vote

Note that update_forward_refs accepts not only globals, but also locals dictionary that you can pass.

So with dummy structure like this:

So you can do something like this:

user.py

from fastapi_users.db import OrmarBaseUserModel
from app.db.base_class import BaseMeta

class User(OrmarBaseUserModel):
    class Meta(BaseMeta):
        tablename = "user"

image.py

import uuid
from typing import Any, Dict, Union

import ormar
from pydantic.typing import ForwardRef

from base_class import BaseMeta
from widget import Widget

UserRef = ForwardRef("User")  # forward ref


class Image(ormar.Model):
    class Meta(BaseMeta):
        tablename = "image"

    id: uuid.UUID = ormar.UUID(primary_key=True, 

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@michaeltoohig
Comment options

@maitham
Comment options

Comment options

You must be logged in to vote
1 reply
@michaeltoohig
Comment options

Answer selected by michaeltoohig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants