I'm creating a website that allows for the creation of events, and those events will be shown on both the home page, and on the events list, so that people can click on the events on view the descriptions of them, as well as check in at the event. I'm having an issue getting a query set within a class to update when a new event is added.
So this function is for our main home page. The query_set updates every time you go back to the page, so when a new event is added, it is shown on this page.
def index(request):
num_future_events = Event.objects.filter(date__gte=today).filter(approved=True).count()
query_set = Event.objects.filter(date__gte=today).filter(approved=True).order_by('date', 'time')[:3]
context = {
'num_future_events': num_future_events,
'query_set': query_set
}
return render(request, 'index.html', context=context)
This is a class for the events list page on my site. It uses a query set but since the class is only ever called once, the query set will only update with the class's initialization.
class EventListView(generic.ListView):
model = Event
query_set = Event.objects.filter(date__gte=today).exclude(approved=False).order_by('date', 'time')[:21]
template_name = 'listPage.html'
def get_queryset(self):
return self.query_set
I was hoping to get some help with making it so when a new event is added, the query set in the EventListView class updates automatically so that it will be displayed on this page.
Any help will be greatly appreciated.