Re: Django Nested Query with Aggregate.Sum()

2018-09-11 Thread mab . mobile . 01
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 =

Re: Django Nested Query with Aggregate.Sum()

2018-09-10 Thread mab . mobile . 01
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 =

Re: Django Nested Query with Aggregate.Sum()

2018-09-10 Thread mab . mobile . 01
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

Re: Django Nested Query with Aggregate.Sum()

2018-09-07 Thread Simon Charette
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

Re: Django Nested Query with Aggregate.Sum()

2018-09-07 Thread mab . mobile . 01
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" }}

Re: Django Nested Query with Aggregate.Sum()

2018-09-06 Thread Simon Charette
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

Django Nested Query with Aggregate.Sum()

2018-09-06 Thread mab . mobile . 01
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