Skip to content Skip to sidebar Skip to footer

Sqlalchemy Doesn't Seem To Like __getattr__()

In my flask sqlalchemy based app, I have a model like this: class Foo(object): start_date = db.Column(db.DateTime()) It works fine but when I use the template engine to print

Solution 1:

SQLAlchemy uses __getattr__ internally. If you overload it, the whole alchemy magic will not work anymore.

The field you are accessing is a DateTime object. If you want to format that into a string in any other way as the default rendering, you should use strftime().

https://stackoverflow.com/a/4830620/3929826 gives an example. https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior has the documenatation on the format string.

Post a Comment for "Sqlalchemy Doesn't Seem To Like __getattr__()"