I have listed all the vendors (users which are staff) in my django tempelate using the following code. In tempelates:
{% for stf in staff %}
<li><a href="{% url 'vendor_products' %}">{{stf.username}}</a></li>
{% endfor %}
In views:
def vendor_products(request):
vend_prod = Product.objects.filter(user_id=request.user.id)
context={
'vend_prod': vend_prod
}
return render(request, "vendor_products.html", context)
The usernames of the suppliers(vendors) is already listed. What I want is the products of the respective vendor will be dispalyed in a separate html page when the vendor username is clicked.
Now the above code is displaying just the products of the user who is logged in.
Here is the products model incase it is needed.
class Product(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
title = models.CharField(max_length=150)
keywords = models.CharField(max_length=255)
description = models.TextField(max_length=255)
image = models.ImageField(null=False, upload_to='images/')
price = models.DecimalField(max_digits=12, decimal_places=2,default=0)
amount = models.IntegerField(default=0)
detail = RichTextUploadingField()