2024-03-29 03:56:08 发布
网友
我有一份产品清单。我想得到它所关联的类别(类别)。 我所做的是:
pro = [] #holds list of all the products for p in pro: for procat in p.get_categories(): print(procat)
但它返回错误:
我从这里得到了方法DJANGO OSCAR
要为文档中指定的ManyToManyField“categories”获取iterable对象,可以尝试调用.all()方法,例如:
for procat in p.get_categories().all():
from oscar.core.loading import get_model Product = get_model('catalogue', 'Product') ProductCategory = get_model('catalogue', 'ProductCategory') cat_ids = Product.objects.values_list('categories', flat=True) categories = ProductCategory.objects.filter(pk__in=cat_ids)
要为文档中指定的ManyToManyField“categories”获取iterable对象,可以尝试调用.all()方法,例如:
相关问题 更多 >
编程相关推荐