开发者

how can I make 'between' query with web2py.DAL?

开发者 https://www.devze.com 2022-12-13 21:46 出处:网络
I\'m trying to make a query function that accepts two datetime.date object(start_date and end_date), and return all records with a related field that\'s between start_date and end_date.

I'm trying to make a query function that accepts two datetime.date object(start_date and end_date), and return all records with a related field that's between start_date and end_date. However, I found nothing like a between function in the web2py manual, so I implement it this way:

        for o in objects:
            # notice that create_time is a datetime field
            create_date = dt.datetime.strptime(o['create_time'], 
                                               "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d")
        if query_dict['create_date_1'] <= create_date <= query_dict['create_date_2']:
            result.append(l)

Doing this is too slow for my application because their can be many objects. So, is there a better way I can imp开发者_StackOverflowlement this using web2py.DAL? Thanks in advance ;)


db((db.mytable.create_date>=query_dict['create_date1'])&(db.mytable.create_date<=query_dict['create_date2'])).select()

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号