Open michaelhjulskov opened 6 years ago
You can try using Q
and F
objects:
from django.db.models import Q, F
Company.objects.filter(
~Q(closingrules__start__lte=now, closingrules_set__end__gte=now)
&
(
Q(
openinghours__weekday=now.isoweekday(),
openinghours__from_hour__lte=now_time,
openinghours__to_hour__gte=now_time,
) | Q(
openinghours__weekday=now.isoweekday(),
openinghours__from_hour__lte=now_time,
openinghours__to_hour__lt=F('openinghours__from_hour'),
) | Q(
openinghours__weekday=(now.isoweekday() - 1) % 7,
openinghours__from_hour__gte=now_time,
openinghours__to_hour__gte=now_time,
)
)
)
If you really need it to be like "property" then you can also try annotating queryset
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: