Greetings everyone, me again!
I would like to ask another question. On this link I have already given my model and it stayed the same: Filtering models in view
I have a question regarding django’s URL dispatcher and how does it work. Here is my code for app/urls.py:
path('', views.IndexView.as_view(), name='index'),
path('company/<int:pk>', views.CompanyDetailsView.as_view(), name='company-details'),
path('companies/', views.CompanyView.as_view(), name='companies'),
path('output-control/', views.OutputControlView.as_view(), name='output-control'),
path('<str:pk>/', views.BillDetailsView.as_view(), name='bill-details'),
path('<str:bill_id>/products', views.ProductsView.as_view(), name='products'),
path('<str:bill_id>/products/<int:pk>', views.ProductsDetailsView.as_view(), name='product-details'),
path('<str:bill_id>/products/<int:pk>/delete', views.ProductDeleteConfirmView.as_view(), name='product-delete'),
path('<str:bill_id>/products/add', views.AddNewProduct.as_view(), name='add-product')
How does django know, which primary key does it need, since both are generated integers and have the same name (<int:pk>
in CompanyDetailsView and ProductsDetailsView). I also have a problem when i want to redirect user from ProductView to the <str:bill_id>/products/add
since ProductView does not return bill_id and I have no idea how to get it. I can only get it from product_list that I pass, but there is a chance that this list is empty so that doesn’t work for me.
<a href="{% url 'add-product' product_list.0.bill.pk %}">
<input type="submit" value="Add new Product">
</a>
Here is code of ProductView:
class ProductsView(generic.ListView):
template_name = 'app/bill_products.html'
context_object_name = 'product_list'
def get_queryset(self):
return Product.objects.filter(bill__eor=self.kwargs['bill_id'])
Is there any way to pass additional arguments to template in ListView?
Thank you all for patience!