You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have put my questions in the comments in the below code. I did not find answers in the documentation.
classUser(Model):
username=CharField(max_length=255, primary_key=True)
organization: ForeignKeyNullableRelation[Organization] =ForeignKeyField(
"models.Organization",
related_name="users",
on_delete=OnDelete.RESTRICT,
null=True,
)
@propertydefis_admin(self):
# Does this load the organization model?# Is there a way to check the foreign key itself for being null without loading the referenced model?returnself.organizationisNonedefmay_create_user(self, user: "User_Pydantic"):
ifself.is_admin:
returnTrueorg=user.organizationiforgisNone:
returnFalse# Is this the correct way to compare two models?# Does tortoise do original-object-return so that we can test using `is`?returnorg==self.organization
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have put my questions in the comments in the below code. I did not find answers in the documentation.
Beta Was this translation helpful? Give feedback.
All reactions