Reputation: 69
My gql model is
start_date = db.DateTimeProperty()
end_date = db.DateTimeProperty()
my class is
class GetHandler(BaseHandler):
def get(self):
promos = Promotion.all()
self.render_response("/admin/promotion/index.html", promos=promos)
if end_date
is expired [end_date<datetime.now
] it should remove from my admin panel.
Upvotes: 0
Views: 61
Reputation: 31572
Based on Tim 's answer:
now = datetime.now() # get current datetime
q = db.Query(Promotion)
q = q.filter('end_date <', now)
for promo in q.run(): # loop over filtered promos
promo.delete() # delete instance from datastore
The documentation discourages the use of fetch instead of run. And it's probably a bad idea to fetch all the promos.
Upvotes: 2
Reputation: 43344
Compare the dates and act accordingly
promos = Promotion.all().fetch() # fetch all promos
now = datetime.now() # get current datetime
for promo in promos: # loop over all promos
if promo.end_date > now: # compare promo date to 'now'
promo.delete() # delete instance from datastore
comparing date(time)s is as simple as using >
or <
Upvotes: 0