There is a view for detail:
def get_viewNum(request, numNom):
md = Nomenclature.objects.get(pk=numNom)
all_changes_for_md = Changes.objects.filter(numNomenclature_id=md.numNom)
return render(request,'Sklad/viewNum.html',context = {'nomenclature':md, 'changes':all_changes_for_md})
There is also a view to display the table:
class TableView(ListView):
model = Nomenclature
context_object_name = 'nm'
template_name = 'Sklad/viewTable.html'
In template, I output a table and I want that when the button is clicked, there is a transition to the detail of the desired nomenclature. My template:
///
{% for item in nm %}
<tr>
<td>{{item.numNom}}</td>
<td>{{item.nameNom}}</td>
<td>{{item.quantity}}</td>
<td>{{item.numPolk}}</td>
<td><a href="{% url 'prosmotr' %}">Просмотр</a></td>
<td><button>Печать</button></td>
</tr>
{% endfor %}
///
How do I pass the desired numNom to the url detail string? If you use this:
...
<td><a href="{% url 'prosmotr' item.numNom %}">Просмотр</a></td>
...
Returns an error:
NoReverseMatch at /table/ Reverse for 'prosmotr' with arguments '('',)' not found. 1 pattern(s) tried: ['news/(?P[^/]+)/\Z']
My urls.py:
urlpatterns = [
path('', home, name='rashod'),
path('add_changes/',CreateChanges.as_view(), name = 'add_changes'),
path('save', save),
path('inventriz/', inventriz, name='invent'),
path('inventriz/inventr', inventr, name='add_invent'),
path('news/<str:numNom>/',get_viewNum, name='prosmotr'),
path('table/', TableView.as_view(), name = 'viewTable')
]