Python & Peewee Query Example Needed

Rob Gaddi rgaddi at technologyhighland.invalid
Tue Feb 17 15:52:27 EST 2015


On Mon, 16 Feb 2015 11:08:18 -0800, Travis VanDame wrote:

> On Monday, February 16, 2015 at 12:35:00 PM UTC-6, Travis VanDame wrote:
>> I'm new to python and peewee and was looking for an example on how to
>> query a mysql table with a datetime column only returning rows that are
>> 30 days old.
> 
> Well this is what I've come up with....
> 
>    @classmethod
>     def get_archive_xml(cls, day_count):
>         return cls.select().where(cls.created +
>         datetime.timedelta(days=int(day_count)) >=
>         datetime.date.today())


Without having actually executed your code, that looks about right.  
There's probably an efficiency pickup to be had only doing the datetime 
math once, but that's a technicality.  Did it work?

  @classmethod
  def get_archive_xml(cls, day_count):
    then = datetime.date.today()-datetime.timedelta(days=int(day_count))
    return cls.select().where(cls.created >= then)

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.



More information about the Python-list mailing list