【发布时间】:2014-06-12 21:49:52
【问题描述】:
我目前正在使用这种关系从模型Product 的特定实例中获取所有图像
product = get_object_or_404(Product, pk=product_id)
images = product.image_set.all()
如果我开始删除和重新排列图像,则该集合不会正确更新自身并包含旧图像并且只是保持其原始顺序。
我相信解决此问题的方法是直接通过Image 模型定义images,而不是作为Product 的集合。
这样做:
images = Image.objects.all()
返回每个产品的所有图像。有没有办法我可以使用类似的方法,直接从Image 模型调用图像,只针对活动产品的图像集?类似于:
images = Image.objects.all(product_id)
【问题讨论】:
标签: python django apache postgresql