Allowing users to own their product in DJango

i want to allow users to view only their own product. But i keep getting this error “”Cannot query “musty474”: Must be “Merchant” instance””.

thanks beforehand.

models.py

class Merchant(models.Model):
    """that means each product have a merchant"""
    owner=models.OneToOneField(User,on_delete=models.CASCADE, null=True, blank=True)

shop_name=models.CharField(max_length=100)
shop_address=models.CharField(max_length=100)
shop_location=models.CharField(max_length=100)
phone_number=models.IntegerField()
email_address=models.EmailField()


def __str__(self):
    return self.shop_name       

class Product(models.Model):
    """That means each product have a category"""
    category=models.ForeignKey(Category,on_delete=models.CASCADE)
    merchant=models.ForeignKey(Merchant, on_delete=models.CASCADE)
    product_name=models.CharField(max_length=100)
    product_image=models.ImageField(upload_to='documents/')
    product_price=models.IntegerField()
    product_quantity=models.IntegerField()
    

views.py

def DashBoard(request):
    products=Product.objects.filter(owner=request.user)
    context={
        'products':products 
    }
    return render(request,'users/dashboard.html',context)
    
    

Answer

It doesn’t look like owner is a member of Product. I think you need something like

products=Product.objects.filter(merchant__owner=request.user)

This looks at the owner field off of the merchant field of Product.