我的模型是这样的:
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]
试试这个:
注释,然后过滤注释。 https://docs.djangoproject.com/en/dev/topics/db/aggregation/
相关问题 更多 >
编程相关推荐