Skip to content
Advertisement

Unsupported lookup ‘category’ for CharField or join on the field not permitted

models.py:

JavaScript

This is my views.py file. I show error at:

bestseller = Product.objects.filter(product__category__icontains=’BestSeller’)

views.py:

JavaScript

I want to Bestseller category product at index.html

I use Django 4 and pyhton 3.9

Advertisement

Answer

You can’t use CharField as a ForeignKey.

It should be like this:

JavaScript

Or like this (the same logic):

JavaScript

This will output all Products in category with name BestSeller.

Advertisement