I have a model with a list of products. Each product has an ID, price, brand, etc. I want return all the objects of the model where brand name is distinct. I am currently using django’s built-in SQLite, so it does not support something like
products = Product.objects.all().distinct('brand')
Is there another way of returning all the objects where the brand name is distinct?
>Solution :
As SQLight doesn’t support .distinct('field') you need to do this directly in python. For example:
products = list({p.brand: p for p in Product.objects.all()}.values())