I’m re-asking this question but with a different framework this time. I have two Models: User and Book with a M2M-relation. I want Book to have an attribute “read” that is True when the relation exists. Is this possible in SQLAlchemy?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Take a look at SQL Expressions as Mapped Attributes. Something like this should do the job for you:
Even though it is not Boolean, you can still use it in the IF statements correctly:
Alternatively you can just add a computed (read-only) property on the Book object, but this will load all the Users into your session: