[Answered ]-List products in relation to the vendor clicked in django ecommerce

1👍

You define a function that takes the primary key (or another unique field like the username) as parameter:

def vendor_products(request, pk):
    vend_prod = Product.objects.filter(user_id=pk)
    context={
        'vend_prod': vend_prod
    }
    return render(request, 'vendor_products.html', context)

In the urls.py you add the parameter to the url:

urlpatterns = [
    path('my/path/<int:pk>/', vendor_products, name='vendor_products')
]

and then you pass the value for the primary key when determining the URL:

{% for stf in staff %}
    <li><a href="{% url 'vendor_products' stf.pk %}">{{ stf.username }}</a></li>
{% endfor %}

Leave a comment