Skip to content

Instantly share code, notes, and snippets.

@abairo
Created May 25, 2018 21:35
Show Gist options
  • Save abairo/ae33d2846efea3d95eb4788618b2cc08 to your computer and use it in GitHub Desktop.
Save abairo/ae33d2846efea3d95eb4788618b2cc08 to your computer and use it in GitHub Desktop.
def jws_filter_date():
if birth_month_begin == birth_month_end:
# Same month
queryset = User.objects.filter(
birth_date__month=birth_month_begin,
birth_date__day__gte=birth_day_begin,
birth_date__day__lte=birth_day_end
)
else:
queryset = User.objects.filter(
# Crossed month
Q(birth_date__month=birth_month_begin, birth_date__day__gte=birth_day_begin) |
Q(birth_date__month=birth_month_end, birth_date__day__lte=birth_day_end) |
# Month intervals
Q( birth_date__month__gt=birth_month_begin ) & Q(birth_date__month__lt=birth_month_end )
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment