选择每个相册中的所有照片 (Django)
我需要一些帮助(抱歉我的英语不好)。
我正在尝试获取每个相册中的所有照片。我不知道如何进行查询。 我需要这些数据(并按属性“顺序”对照片进行排序,这会很棒)。
House1-title
photo1: descritpion photo2: descritpion
photo3
: descritpion
House2-title
photo1: descritpion
photo2: descritpion
photo3: descritpion
模型(略)是这样的,比较多方便查询吗?哪个更有效率? (我知道,最好的解决方案是使用内存缓存)。
选项A:
class House(ImageModel):
title = models.CharField(max_length=25)
photos = models.ManyToManyField('Photo')
class Photo(ImageModel):
photo = models.ImageField(upload_to='photos/originals')
description = models.CharField(max_length=100)
order = models.IntegerField()
选项B:
class House(ImageModel):
title = models.CharField(max_length=25)
class Photo(ImageModel):
house = models.ForeignKey(House)
photo = models.ImageField(upload_to='photos/originals')
description = models.CharField(max_length=100)
order = models.IntegerField()
谢谢!
I need some help (sorry for my poor english).
I 'm trying to get all photos from each album. I don't know how to make the query.
I need this data (and order the photos by atribute "order" it will fantastic).
House1-title
photo1: descritpion
photo2: descritpion
photo3: descritpion
House2-title
photo1: descritpion
photo2: descritpion
photo3: descritpion
The model (abbreviated) looks like this, which is more easy to make the query? and wich is more efficient? (i know, the best solution is using memcache).
Option A:
class House(ImageModel):
title = models.CharField(max_length=25)
photos = models.ManyToManyField('Photo')
class Photo(ImageModel):
photo = models.ImageField(upload_to='photos/originals')
description = models.CharField(max_length=100)
order = models.IntegerField()
Option B:
class House(ImageModel):
title = models.CharField(max_length=25)
class Photo(ImageModel):
house = models.ForeignKey(House)
photo = models.ImageField(upload_to='photos/originals')
description = models.CharField(max_length=100)
order = models.IntegerField()
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
选项 B. 是正确的方法。
option B. is the right way.