且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

django - 从多对一关系中获取对象集

更新时间:2022-12-30 18:37:00

您就快到了.你应该使用 photo_set 而不是 image_set

You are almost there. you should be using photo_set instead of image_set

>>>t_album.photo_set.all() 

即带有 _set 的小写模型名称

i.e the lowercase modelname with _set

如果您想要 1 个查询中的照片列表,

If you want the list of photos in 1 query,

photos = Photo.objects.filter(album__user__username='tika')