Replies: 1 comment 3 replies
-
Take a look here : https://tortoise.github.io/models.html?h=type#improving-relational-type-hinting in your example i think you can fix it in this way: class User(Model):
id = fields.UUIDField(pk=True)
email = fields.CharField(max_length=255, unique=True, index=True)
organization: fields.ForeignKeyRelation[Organization] = fields.ForeignKeyField(
"user.Organization", related_name="users"
)
# for type hinting
organization_id: fields.ForeignKeyRelation[Organization]
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey all, I'm setting up a model like this
It autogenerates the
user.organization_id
on the model and it works great, but when I run mypy type hinting, it complains the field doesn't exist with an errorI realize I can fetch the organization model, but this is inefficient, I don't want to run the extra query and/or
JOIN
for that. Is there a different way to define this such that field is explicitly declared? I can add a@property
for it or something, but I thought I'd check if there was a nicer way to handle it.Thanks for the great library!
Beta Was this translation helpful? Give feedback.
All reactions