Hi Manuelf
I understand what you say.
Now, I think It's not the problem of Querym , too.
The problem is that field data is not displayed in HTML.
You use the wrong variable name "office" in Template.
try this.
(View)
context['office'] = ....
↓
context['offices'] = ...
(Template)
× {% for office in office.all %}
↓
{% for office in offices %}
regards
Arisophy
2021年3月20日(土) 7:31 Manuel Buri <[email protected]>:
> *Booking Model*
> from django.db import models
> from django.utils import timezone
> from users.models import Account
> from organization.models import Organization, Office
>
>
> class Booking(models.Model):
> LOCATION_OPTIONS = (
> ('H', 'Home Office'),
> ('O', 'Office'),
> ('N', 'Not indicated'),
> )
> account = models.ForeignKey(Account,
> on_delete=models.CASCADE)
> organization = models.ForeignKey(Organization,
> on_delete=models.CASCADE)
> office = models.ForeignKey(Office,
> on_delete=models.CASCADE)
> booking_time = models.DateTimeField(default=timezone.now)
> location = models.CharField(max_length=1,
> choices=LOCATION_OPTIONS)
> class Meta:
> unique_together = ('account', 'booking_time',)
>
> *View*
> def overview_view(request):
>
> context = {}
>
> if request.method == 'GET':
> start_date = None
> end_date = None
> if request.is_ajax():
> booking_times = request.GET.get('day')
> start_date = datetime.strptime(booking_times, "%Y-%m-%d")
> end_date = start_date + timedelta(days=4)
> start_date = start_date.replace(hour=0, minute=0, second=0,
> microsecond=0, tzinfo=pytz.utc)
> end_date = end_date.replace(hour=0, minute=0, second=0,
> microsecond=0, tzinfo=pytz.utc)
>
> context['bookings']=Booking.objects.filter(
> Q(organization_id=request.user.organization_id), Q(booking_time__range =
> (start_date, end_date))
> context['office'] =
> Office.objects.filter(organization_id__exact=request.user.organization_id)
>
> return render(request, 'overview/overview.html', context)
> return render(request, 'overview/overview.html', context)
>
> haha sorry for not using pastebin before :D
>
> Thank you so much.
>
> Best wishes,
>
> Manuel
>
>
>
> Manuel Buri
> T: +41 79 933 01 11
> M: [email protected]
> W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>
>
>
> On Fri, 19 Mar 2021 at 23:22, Héctor Alonso Lozada Echezuría <
> [email protected]> wrote:
>
>> Can you share your "Booking" model and the view (function or class) that
>> renders the template?, and I beg you, please use pastebin.com for share
>> your code :D
>>
>> El vie, 19 mar 2021 a las 16:17, Manuel Buri (<[email protected]>)
>> escribió:
>>
>>> @[email protected] and [email protected]
>>> your suggestion is unfortunately not working too
>>>
>>> @All:
>>> So as said my queryset is not empty, meaning that the query works.
>>> However, the results is not in the rendered HTML file.
>>> This would imply that with my template is something wrong, don't you
>>> think?
>>>
>>> {% for office in office.all %}
>>> <small>{{ office.office_name }}</small>
>>> {% for booking in bookings %}
>>> <div class="client-item">
>>> <div class="client-text">
>>> <p class="name">{{ booking.account.first_name }} {{
>>> booking.account.last_name }}</p>
>>> {% if booking.get_location_display == 'House' %}
>>> <p class="sub-title">🏢 {{ booking.get_location_display
>>> }}</p>
>>> {% elif booking.get_location_display == 'Home' %}
>>> <p class="sub-title">🏠 {{ booking.get_location_display
>>> }}</p>
>>> {% else %}
>>> <p class="sub-title">🤔 {{ booking.get_location_display
>>> }}</p>
>>> {% endif %}
>>> </div>
>>> </div>
>>> {% endfor %}
>>> {% endfor %}
>>>
>>>
>>> What do you think?
>>>
>>> Thank you so much for your help !!!!!
>>>
>>> Best wishes,
>>>
>>> Manuel
>>>
>>>
>>>
>>> Manuel Buri
>>> T: +41 79 933 01 11
>>> M: [email protected]
>>> W: www.manuelburi.com <http://manuelburi.com/?utm_source=gmail>
>>>
>>>
>>> On Fri, 19 Mar 2021 at 22:51, Thomas Lockhart <[email protected]>
>>> wrote:
>>>
>>>> Why use Q? afaict simple filter syntax should get you what you want.
>>>>
>>>> Booking.objects.filter(organization_id=request.user.organization_id,
>>>> booking_time__range= (start_date, end_date))
>>>>
>>>> Not sure if this will get you closer to the query you expect.
>>>>
>>>> You might also find it useful to use "./manage.py shell" to test the
>>>> queries by hand. Import a few models, put in “11” for the organization_id,
>>>> and see what happens.
>>>>
>>>> - Tom
>>>>
>>>> > On Mar 19, 2021, at 2:11 PM, Manuel Buri <[email protected]>
>>>> wrote:
>>>> >
>>>> > I want to fetch all bookings for the users organization_id between
>>>> start_date and end_date.
>>>> > I am achieving this via this queryset, however, as soon as I add the
>>>> second filter (bold), it is not rendered in the template anymore and I,
>>>> therefore, do not see it in my HTML file.
>>>> > context['bookings']=Booking.objects.filter(
>>>> Q(organization_id=request.user.organization_id), Q(booking_time__range=
>>>> (start_date, end_date)))
>>>> >
>>>> > Thank you so much for your help.
>>>> > Best wishes,
>>>> >
>>>> > Manuel
>>>> >
>>>> >
>>>> >
>>>> > Manuel Buri
>>>> > T: +41 79 933 01 11
>>>> > M: [email protected]
>>>> > W: www.manuelburi.com
>>>> >
>>>> >
>>>> > On Fri, 19 Mar 2021 at 22:07, Anornymous u <[email protected]>
>>>> wrote:
>>>> > I mean what you want to fetch and the conditions
>>>> >
>>>> > On Fri, Mar 19, 2021, 16:01 Manuel Buri <[email protected]>
>>>> wrote:
>>>> > Hi,
>>>> >
>>>> > I am having this query set in my view:
>>>> > context['bookings']=Booking.objects.filter(
>>>> Q(organization_id=request.user.organization_id), Q(booking_time__range=
>>>> (start_date, end_date)))
>>>> >
>>>> > It produces a non-empty query set!
>>>> > However, I am NOT able to display it in my template.
>>>> >
>>>> > If I get rid of Q(booking_time__range= (start_date, end_date) and
>>>> only do:
>>>> > context['bookings']=Booking.objects.filter(
>>>> Q(organization_id=request.user.organization_id))
>>>> > then it is also non-empty AND it is displaying it in my template.
>>>> >
>>>> > What am I missing here?
>>>> >
>>>> > Thank you 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/76f85c72-19f9-4ad3-a39b-01dc60aa6da5n%40googlegroups.com
>>>> .
>>>> >
>>>> > --
>>>> > You received this message because you are subscribed to a topic in
>>>> the Google Groups "Django users" group.
>>>> > To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/django-users/2DC9EY75yuM/unsubscribe.
>>>> > To unsubscribe from this group and all its topics, send an email to
>>>> [email protected].
>>>> > To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/CAMXTB%3DcsfYRqGPbhXncaHNTjKqVhgskST8BDEAY-2fYonemfdg%40mail.gmail.com
>>>> .
>>>> >
>>>> > --
>>>> > 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/CACx7KOQEEWWNu6hQwMXdEP_nZ6%2Bex9HZ9KEiVubrvd89%3DTP%3DuQ%40mail.gmail.com
>>>> .
>>>>
>>>> --
>>>> You received this message because you are subscribed to a topic in the
>>>> Google Groups "Django users" group.
>>>> To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/django-users/2DC9EY75yuM/unsubscribe.
>>>> To unsubscribe from this group and all its topics, send an email to
>>>> [email protected].
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/7C87F855-5ECE-4470-A8CA-916B64F7CFF5%40gmail.com
>>>> .
>>>>
>>> --
>>> 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/CACx7KOS-9b1UP%3D4t4jUOHgn8co_19W2CCRCQWR%3DCWwLHWR%2BsFQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CACx7KOS-9b1UP%3D4t4jUOHgn8co_19W2CCRCQWR%3DCWwLHWR%2BsFQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>
>>
>> --
>> Héctor Alonso Lozada Echezuría
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/django-users/2DC9EY75yuM/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CADTS2YzEw3jqctmHaWfhhZagmy0VW8-XvppHQtHTCAzmSf3v-Q%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CADTS2YzEw3jqctmHaWfhhZagmy0VW8-XvppHQtHTCAzmSf3v-Q%40mail.gmail.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/CACx7KORxjdPeqw_UZoTC0eRp92ngZa-bX%3DDUd3sf3-59PY4kYg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CACx7KORxjdPeqw_UZoTC0eRp92ngZa-bX%3DDUd3sf3-59PY4kYg%40mail.gmail.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%2B2LtkBMZEeKGSr%2Bvza5wzc3hxjgTqVXJmfmz0UBWc47nn_YVA%40mail.gmail.com.