Hi, Manuei I think , At first, you shoukd check the value of "request.user.organization_id" . Next, try to use Q if the value is valid.
context['bookings'] = Booking.objects.filters(Q((organization_id=request.user.organization_id) & Q(booking_time=booking_date)) https://docs.djangoproject.com/en/3.1/topics/db/queries/#complex-lookups-with-q regards Arisophy 2021年3月19日(金) 7:59 Manuel Buri <[email protected]>: > Hi folks, > can you please help me with this. > > I am trying to get the context working where I filter for the > organization_id as well as the booking_time. Both queries are not empty, > however, only the context without the booking_time filter works while > rending in html. > > Code: > @login_required > def overview_view(request): > > context = {} > booking_date = None > > if request.method == 'GET': > if request.is_ajax(): > booking_time = request.GET.get('day') > booking_time = datetime.strptime(booking_time, "%Y-%m-%d") > booking_date = booking_time.replace(hour=0, minute=0, second=0, > microsecond=0, tzinfo=pytz.utc) > > *THIS ONE DOES NOT WORK* > > *context['bookings'] = > Booking.objects.filter(organization_id=request.user.organization_id).filter( > booking_time=booking_date)* > > *THESE DO WORK:* context['bookings'] = > Booking.objects.filter(organization_id=request.user.organization_id) > return render(request, 'overview/overview.html', context) > > return render(request, 'overview/overview.html', context) > > > Thank you so much for your help. > > Manuel > > -- > 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 view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/8afb07f4-10b2-4145-ab23-6fe9bb41c599n%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/8afb07f4-10b2-4145-ab23-6fe9bb41c599n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B2LtkC9Qsf3oxm5bRLsL%2BECUtDqB_e2ycGnesB69zWkVoNhWg%40mail.gmail.com.

