1👍
I think you’re looking for filter.
galleries_with_selected_collection = PhotoGallery.objects.filter(collection=selected_collection)
# context must be a dict, not a list
context = {
'galleries': galleries_with_selected_collection
}
You’re pulling in PhotoGallery objects not images or collections. Those are attributes of your PhotoGallery. So you’ll need to grab photo galleries with your chosen collection, then grab their image attribute.
And to clarify about creating a model for each collection:
You can split your collections into a Collection model. You wouldn’t need to create a new model for each collection, you just add each collection instance to the collection table. Then your photo gallery would have a foreign key to the collection. I would probably go one step further and separate your images into their own model too.
Source:stackexchange.com