Nancy Andeyo <[email protected]> writes:
> However, the part with problems is this one: .filter(func.strftime('%m',
> Event.event_date = datetime.today().strftime('%m'))) where the aim to
> filter out events that will take place in the current month. This is the
> section that I posted, yet I needed to post the entire query for what I am
> intending to achieve is understood.
I can't say if the typos are due to you rewriting the cide in these
messages, or if instead they are effectively present in the real code,
but also the above is not correct:
.filter(func.strftime('%m', Event.event_date =
datetime.today().strftime('%m')))
This should raise a syntax error when evaluated by Python...
For comparison, the following complete script works for me:
from datetime import date
from pprint import pprint
from sqlalchemy import create_engine
from sqlalchemy import func
from sqlalchemy.orm import Session
from sol.models import Tourney
engine = create_engine('sqlite:///development.db')
session = Session(engine)
q = session.query(Tourney)
q = q.filter(func.strftime('%m', Tourney.date) == date.today().strftime('%m'))
pprint([(t.description, t.date) for t in q.limit(3).all()])
and emits
[('2° Torneo', datetime.date(2001, 4, 1)),
('7° Torneo', datetime.date(2004, 4, 24)),
('7° Torneo', datetime.date(2005, 4, 30))]
Hope this helps,
ciao, lele.
--
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
[email protected] | -- Fortunato Depero, 1929.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sqlalchemy/87pm8ier3i.fsf%40metapensiero.it.