I have such model:
class Test(db.Model, UnicodeMixin):
__tablename__ = 'test'
id = db.Column(db.Integer, primary_key=True)
subject = db.Column(db.String(512), nullable=False)
additional = None
def __unicode__(self):
return u'<Test {0}>'.format(self.id)
Some code generate RAW SQL for very difficult SELECT
from db with additional dynamic data.
For example it like:
db.session.query(Test).from_statement("SELECT test.id AS test_id, test.subject AS test_subject, 99 AS additional FROM test").all()
It generate list of python objects Test
, but how I can fill attribute additional
for these python objects?
I don't want store NULL
column additional
in database.
I want create dynamic additional data with SQL and add it to python objects.
Help please.
Thanks.
Do this:
db.session.query(Test, "additional").from_statement(
"""
SELECT test.id AS test_id, test.subject AS test_subject, 99 AS additional
FROM test
"""
).all()
It will return a list of tuples in the (Test object,additional) structure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With