Thank you, i will solve it with Q, it makes sense and will make it clear in 
future edits.

On Tuesday, 9 October 2018 21:50:50 UTC+2, Mateusz wrote:
>
> There are many ways to resolve your problem. According to 
> https://stackoverflow.com/questions/769843/how-do-i-use-and-in-a-django-filter
>  this 
> should work:
> from django.db.models import Q
> date_range = Q(date_stop__range=[today, today_plus_ten])
> date_none = Q(date_start=today, date_stop=None)
> coursedates_ending = CourseDate.objects.filter(date_range & date_none)
>
> You can also consider populating your date_stop with the same day as 
> date_start if it's not specified. Personally, I get take that as the best 
> answer. You can do that either with pre_save signal, which would do it even 
> if that's added from Django Admin page or shell (docs 
> <https://docs.djangoproject.com/en/2.1/ref/signals/#django.db.models.signals.pre_save>)
>  
> or form validation only for form(s) (docs 
> <https://docs.djangoproject.com/pl/2.1/ref/forms/validation/>).
>
> BTW: Notice, there is no need for X.objects.all().filter(...), you can 
> just use X.objects.filter(...).
>
> Notice: This answer was removed and edited.
>
> W dniu wtorek, 9 października 2018 18:23:38 UTC+2 użytkownik Moreplavec 
> napisał:
>>
>> Hello,
>>
>> I have DB with courses and each course has many dates (with starting and 
>> ending date). I'm trying to make report with starting and ending course 
>> dates in 10 days. The problem is, that one day courses usually don't have 
>> ending date (date_stop) filled. Right now i'm using query:
>>
>> coursedates_ending = 
>> CourseDate.objects.all().filter(date_stop__range=[today, 
>> today_plus_ten]).order_by('date_stop')
>>
>> to get courses ending in 10 days. But is it possible to include courses 
>> without ending date and for this courses to look at the date_start? Or is 
>> it possible to update coursedates_ending with such courses?
>>
>> Thanks for help or tips how to do it django-way.
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e6ae4aa5-d105-4a4f-a860-d7639f4c9706%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to