I have a list of all products which belong to different categories.
model.py
class Product(models.Model):
product_name = models.CharField(max_length=50,null=True, blank=True)
details = models.CharField(max_length=100, null=True, blank=True)
company_name = models.CharField(max_length=50,null=True, blank=True)
category = models.ForeignKey(ProductClass,null=True, blank=True)
Category is a ForeignKey
of ProductClass
.
Now I want a list of all different categories. I do not want a list of repetitive categories. For that I tried obj = CustomerLeads.objects.all()
obj = Product.objects.all()
c = []
for i in obj:
c.append(i.item_required)
cat = set(c)
return JsonResponse({'data':cat})
I am getting error set([<ProductClass: accessories>, <ProductClass: other>]) is not JSON serializable
How can I get a list of all different categories?