请看一下这些模型:
class Album(models.Model):
user = models.ForeignKey(User)
name = models.CharField(max_length=200)
pub_date = models.DateTimeField(default=datetime.now)
class Photo(models.Model):
album = models.ForeignKey(Album, default=3)
image = models.ImageField(upload_to=get_upload_file_name)
caption = models.CharField(max_length=200)
pub_date = models.DateTimeField(default=datetime.now)
如何获取特定相册的照片集???以及如何从照片实例本身获取相册?
我试过这个:
# To get the set of photos from the user (tika) album:
>>>t = User.objects.get(username='tika')
>>>t_album = Album.objects.get(user=t)
>>>t_album
<Album: tika_album>
>>>t_album.image_set.all()
AttributeError: 'Album' Object has no attribute 'image_set'
请引导我走向正确的方向。谢谢你。