title: Django filter in a View
body: <p>I'm just starting on Django, and currently stuck on a seemingly simple requirement/behaviour. I want a page rendered with a filtered set of entries based on the class's ForeignKey, and called from a rendered view of that other class.</p>
  
  <p>A simplified version of my model.py is:</p>
  
  <pre><code>from django.db import models
  
  class BookDay(models.Model):
      bookdate = models.DateField()
      bookevent = models.CharField(max_length=255)
  
  class BookTime(models.Model):
      booktime = models.TimeField()
      bookdate = models.ForeignKey(BookDay, on_delete = models.CASCADE)
  </code></pre>
  
  <p>My view.py reads:</p>
  
  <pre><code>from django.http import HttpResponse
  from django.views import generic
  
  from .models import BookDay, BookTime
  
  class DayView(generic.ListView):
      template_name = 'booking/days.html'
      context_object_name = 'bookdate_list'
  
      def get_queryset(self):
       return BookDay.objects.order_by('bookdate')
  
  class TimeView(generic.ListView):
      model = BookDay 
      template_name = 'booking/booktimes.html'
      context_object_name = 'booktimes_list'
      def get_queryset(self):
       return BookTime.objects.filter(bookdate=bookday_id).order_by('booktime')
  </code></pre>
  
  <p>My urls.py contains:</p>
  
  <pre><code>    from django.urls import path
      from . import views
  
      app_name = 'booking'
      urlpatterns = [
          path('', views.DayView.as_view(), name='bookdays'),
          path('&lt;int:pk&gt;/', views.TimeView.as_view(), name='booktimes'),
      ]
  </code></pre>
  
  <p>The referenced days.html renders a set of links per this fragment:</p>
  
  <pre><code>{% for entry in bookdate_list %}
      &lt;li&gt;&lt;a href="{% url 'booking:teetimes' entry.id %}"&gt;{{ entry.bookevent }}&lt;/a&gt;&lt;/li&gt;
  {% endfor %}
  </code></pre>
  
  <p>On clicking any of the resulting links, the failure manifests as <code>name 'bookday_id' is not defined</code>.</p>
  
  <p>I can put a fixed integer in place of <code>bookday_id</code> in views.py above, and it works fine (for that ForeignKey only, obviously). Also, I've played around with the filter() parameter name, the relevant url, and the html extensively to no avail.</p>
  
  <p>How should I parameterise this to take the clicked link and filter the BookTimes entries correctly? Should I use Django-filter for this, or can it be done natively in Django?</p>