FINAL SOLUTION / SOLVED
A bit of a more complex single query...
VIEW
def winery_events_view(request):
events =
WineryEvents.objects.filter(publish='Y').filter(event_date__gte=datetime.now()).order_by('event_date').annotate(seats_remaining
= F('seating')-Sum('reservations__seats_reserved')
Ok, data transfer error fixed and data now in table. However, I am still
not getting a value for {{i.seats_remaining}}. It comes out blank.
I had an error in the view that I corrected as below but still does not
give results.
def winery_events_view(request):
winery_events =
WineryEvents.o
Hello Simon,
I tried implementing your recommendations today and all appeared to go well
except that I was not getting any results from the query for remaining
seating on the html template. I took a look at my reservation table and the
data was gone. I had the data in an original table I copie
The annotate(seats_remaining=...) will add a `seats_remaining` attribute to
Event
instances returned from the queryset so you should be able to use
{{i.seats_remaining }}
Cheers,
Le vendredi 7 septembre 2018 04:38:05 UTC-4, mab.mo...@gmail.com a écrit :
>
> Thank you Simon.
>
> I will take a lo
Thank you Simon.
I will take a look at annotations.
How would I represent seats remaining in the template for loop? Here is
what I have so far.
#
{% for i in events %}
{{ i.event_date|date:"l M j, Y" }} {{
i.event_time|date:"g:i A" }}
{{i.event_type|t
Hello there,
You should be able to achieve what you're after by using annotations[0].
In your case you'll want to declare your Event and Reservation relationship
explicitly by using
a ForeignKey
class Event(models.Model):
...
seating = models.PositiveIntegerField(default=0)
class Reser
QUESTION
I have an application that will make on-line reservations for a series of
weekly events. I would like to display the list of upcoming events in an
html template with the number of remaining seats available in a single html
page. I was able to create views to display the list of upcomi
7 matches
Mail list logo