I have this view info:
def tracker(request):
object = Fcttracker.objects.all()[:1].get()
object_id = object.rbid
prev_id = Fcttracker.objects.all()[:1].get().rbid
next_id = Fcttracker.objects.filter(rbid__exact=object_id+1).get().rbid
context = {'data': object,
'prev': prev_id,
'next': next_id,
}
return render(request, 'tracker.html', context)
def show_tracker(request, id):
try:
object = Fcttracker.objects.filter(rbid__exact=id)
except Fcttracker.DoesNotExist:
raise Http404("Record does not exist")
prev_id = id - 1
next_id = id + 1
context = {'data': object,
'prev': prev_id,
'next': next_id,
}
return render(request, 'tracker.html', context)
Tracker is called first because there is no id. If the next and previous are clicked it’s supposed to take the rbid and then call show_tracker with that id. But I get this error:
Reverse for 'tracker' with arguments '('',)' not found. 2 pattern(s) tried: ['redbud_site/tracker/(?P<id>[0-9]+)/$', 'redbud_site/tracker/$']
Is that because I originally called it with no arguments. I would have thought one way or the other it would have found one of those. My url pattern for this is:
urlpatterns = [
path('', views.index, name='index'), path('cma_unassigned/', views.cma_unassigned, name='cma_unassigned'),
path('tracker/', views.tracker, name='tracker'),
path('tracker/<int:id>/', views.show_tracker, name='tracker'),
]
I was hoping that would catch when to insert an id. I’m trying to have a next/previous buttons to move the record set forward thru the model or queryset. And thought I should call each record by it’s ID.