0
我的模式是这样的:让产品与至少一个图像
class Product(models.Model):
name = models.CharField(max_length=100)
...
class ProductImage(models.Model):
thumbnail = models.ImageField(...)
...
product = models.ForeignKey(Product, related_name='images', blank=True, null=True)
我需要改变以下使它只取产品与至少一个图像:
products = Product.objects.filter(status='PU').order_by('?')[:4]
不完全是,需要改变' 'productimage'',以符合他'related_name',所以'IMAGE_COUNT =计数(' 图像)' – Shay
@ shay,很好,赶上! –