我有两个型号第一个元素:通过ForeignKey的
Cars(models.Model):
many-many fields
Pictures(models.Model):
car = models.ForeignKey(Cars, related_name='pictures')
img-field, etc
如何让意见轿车的第一张图片(它的一个画廊,很多汽车,我需要先预览图片)?我使用:
car = Cars.objects.all()[:6].values('id', 'pictures__image')
在DB我有一个汽车行驶4张图片,视图返回4个字典具有相同ID和不同的图像,但我需要一个ID - 一个图片。这个怎么做? (不是OneToOneField,因为有一辆车的许多照片)。
感谢
车= Cars.objects.all(): 1] .values('id','pictures__image')。order_by('id') – catherine 2013-03-07 18:08:56
@catherine它返回1'汽车',但我需要6.和每张车的一张图片 – tim 2013-03-07 18:16:23
啊..ok,我误解了你的题。我会尝试找到 – catherine 2013-03-07 18:26:55