0
다른 카테고리에 속한 모든 제품의 목록이 있습니다.장고의 모든 제품에서 다른 카테고리 찾기
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)
카테고리 ProductClass
의 ForeignKey
입니다.
이제 모든 다른 카테고리 목록을 원합니다. 나는 반복적 인 범주의 목록을 원하지 않는다. 이를 위해 내가 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})
을 시도 나는
이가 어떻게 모든 다른 카테고리의 목록을 얻을 수 있습니다 set([<ProductClass: accessories>, <ProductClass: other>]) is not JSON serializable
오류는 무엇입니까?
오류가 조용 분명,'설정 ([, ])'당신이 보내려고 할 때 직렬화 분명히 비입니다 ProductClass 인스턴스의 설정 그들을 통해 JsonResponse. 이름, ID 및 필요한 모든 데이터가 포함 된 카테고리 사전을 보내보십시오. –
일부 샘플 코드로 도울 수 있습니다 –
'CustomerLeads'는 무엇을해야합니까? 그냥'ProductClass.objects.all()'아닌가요? 이 목록을 어디에서 얻으려고합니까? ... – Sayse