Python / Sqlalchemy Format Daterange Object
I am using the DateRange column type to save reservations for a booking system. My DB is PosgreSQL and I use Python 3 with Flask and SQLAlchemy. Even though it should be best pract
Solution 1:
SQLAlchemy documentation hints that the range types are a Psycopg feature, so looking at their documentation for the objects in question you will find that Range
objects have attributes lower
and upper
that hold the bounds. With them it is straightforward to produce a list of tuples:
fmt = '%Y-%m-%d'
bookings = [(format(bdate.lower, fmt), format(bdate.upper, fmt))
for bdate in room.RoomObject_addresses_UserBooksRoom]
Post a Comment for "Python / Sqlalchemy Format Daterange Object"