Currently you'd have to code a view in the database (or simply a "string" 
condition to pass on) to achieve that. 

date.today() - timedelta(something) is a python "fixed" value that doesn't 
get re-evaluated at runtime by the database substituting the "something" 
for each value of every row.

If you need the structure to be portable and absolutely need to have a 
single query fetching all of this, you need to change your db structure.

If you're going to run always on a "fixed" db engine you could write 
something exploiting the functionalities of that db engine.

Remember that most of the times is easier (and the resources negligible) to 
fetch rows from the db and filter them with python.

cards2learn = db((db.groupCards.card_id == db.card.id) \
        & (db.groupCards.studyGroup_id == auth.user.studyGroup_id) \
        & (session.chosenSubject_id == db.card.subject_id) \
        & (db.userCard.card_id == db.card.id)
        & (db.userCard.stage <= 5) \
        #& (db.userCard.lastTimeLearned < (date.today() - 
timedelta(days=(1))))
        ).select(db.userCard.ALL,db.
>
> card.ALL,db.groupCards.ALL, left=db.userCard.on((db.userCard.card_id == db
> .card.id)))
>
> cards2learn.exclude(lambda row: row.usercard.lasttimelearned < request.now 
> - timedelta(days=row.usercard.stage))
>





 should work. (totally untested)

On Thursday, July 26, 2012 5:23:51 PM UTC+2, jw wrote:
>
> Ok guys... I did step for step and now the query works for the stage 
> (progress).
> The second thing (stage is multiplicator for time) I have no glue how to 
> move on.
>
> cards2learn = db((db.groupCards.card_id == db.card.id) \
>         & (db.groupCards.studyGroup_id == auth.user.studyGroup_id) \
>         & (session.chosenSubject_id == db.card.subject_id) \
>         & (db.userCard.card_id == db.card.id)
>         & (db.userCard.stage <= 5) \
>         & (db.userCard.lastTimeLearned < (date.today() - 
> timedelta(days=(1))))
>         ).select(db.userCard.ALL,db.card.ALL,db.groupCards.ALL, 
> left=db.userCard.on((db.userCard.card_id == db.card.id)))
>
> timedelta(days=(1)) should be timedelta(days=(db.userCard.stage)) but it 
> says:
> <type 'exceptions.TypeError'> unsupported type for timedelta days 
> component: Field
> How do I use the db.userCard.stage in timedelta (stage is an integer field 
> in the table)?
>
> Many thanks for the previous answers!
>

-- 



Reply via email to