You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to do something like this:
open_shops = Shop.objects.filter(is_open=True)
But how ? :)
and I'd like to add is_open to my model.
update:
Im thinking something like adding this to my Shop model:
@property
def tz_info(self):
return geocoders.GoogleV3().timezone((self.location.y,self.location.x))
@property
def is_open(self):
now = datetime.now(tz=self.tz_info)
now_time = time(now.hour, now.minute, now.second)
if not ClosingRules.objects.filter(company=self, start__lte=now, end__gte=now).count():
ohs = OpeningHours.objects.filter(company=self)
for oh in ohs:
is_open = False
# start and end is on the same day
if (oh.weekday == now.isoweekday() and oh.from_hour <= now_time and now_time <= oh.to_hour):
is_open = oh
# start and end are not on the same day and we test on the start day
if (oh.weekday == now.isoweekday() and oh.from_hour <= now_time and ((oh.to_hour < oh.from_hour) and (now_time < time(23, 59, 59)))):
is_open = oh
# start and end are not on the same day and we test on the end day
if (oh.weekday == (now.isoweekday() - 1) % 7 and oh.from_hour >= now_time and oh.to_hour >= now_time and oh.to_hour < oh.from_hour):
is_open = oh
# print " 'Special' case after midnight", oh
if is_open is not False:
return oh
return False
The text was updated successfully, but these errors were encountered:
I would like to do something like this:
open_shops = Shop.objects.filter(is_open=True)
But how ? :)
and I'd like to add is_open to my model.
update:
Im thinking something like adding this to my Shop model:
The text was updated successfully, but these errors were encountered: