On 7 Sep 2009, at 16:35 , Rob B (uk) wrote: > Oh that just makes my brain hurt lol
It's not very hard to represent if you just use a few schemas: This is the range of the promotion: A B |------------------| And these are the possible research ranges relative to the promotion (actual values aren’t relevant): a b |----------| a b |--------------------------| a b |--------------| a b |------------| a b |--------| a b |------------| Of these, only the last two won't "match" the promotion. What's the difference between the last two ranges and the previous 4? Well in the second-to- last, b < A, and in the last a > B. That's pretty much all. So the matching condition is that we don't want either b < A or a > B: `not (b < A or a > B)` ≡ `(not b < A) and (not a > B)` ≡ `b > A and a < B` Since we're performing the search on the promotion, we want the promotion's data first so we revert both operation and get `A < b and B > a`. A and B are the start and end dates of promotion, and a and b are the start and end dates of our search, so in Python terms we need a promotion matching `start_date < search.end_date and end_date > promotion.start_date` which in Django filter terms becomes `start_date__lt=search.end_date, end_date__gt=search.start_date` And there you are. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---