I want to have a button which links to page make-appointment
template.html
{% for key, value in closest_free_spots.items %}
...
<a href="{% url 'make-appointment' value.pk %}"><button type="button">{{ value.datetime }}</button></a>
urls.py
url(r'^umowienie-spotkania/(?P<pk>\d+)/$', TestPy.views.MakingAppointmentView.as_view(),
name='make-appointment'),
However when I try to launch it, I get error:
Reverse for 'make-appointment' with arguments '('',)' not found. 1 pattern(s) tried: ['umowienie-spotkania/(?P<pk>\\d+)/$']
It looks like the value.pk is not correct, but when I print it one line above, it gives correct value (i.e. 4).
What is the problem? What I'm missing?
closest_free_spots definition - value is object from CalendarFreeSlot model
closest_free_spots = {
lawyer: TestPy.models.CalendarFreeSlot.objects.filter(Q(lawyer_id=lawyer) & Q(is_available=True)).first() for
lawyer in object_list}
models.py
class CalendarFreeSlot(models.Model):
lawyer_id = models.ForeignKey('MyUser', on_delete=models.PROTECT)
datetime = models.DateTimeField()
is_available = models.BooleanField(default=True)