I've added photologue to my project, because it does 99% of the things I was trying to achieve by myself.
Now I need to connect the uploaded images and images in galleries to my posts. This is why I've added a ManyToMany field to the photologue Photo model
Class ImageModel(models.Model):
post_images = models.ManyToManyField(Post, blank=True)
And will do the same to the Gallery model
class Gallery(models.Model):
post_gallery = models.ManyToManyField(Post, blank=True)
Now my idea is to be able to add a gallery and/or specific images to my post . Both options should be available.
The queryset I would like to have is to get all the individual images, that are attached to the post and also all the images in the gallery if a gallery is attached. Then to pass and render them to the page in some sort of gallery (Slider, carousel or something else). I'd like to be able to get them in the template with one for loop, so I think the queryset have to be one.
I have a view that renders the specific page type and I don't know if I should include the queryset and context in this function or to create a new one for the images. And how to do it.
def post(request, slug):
post = get_object_or_404(Post, post_slug=slug)
context = {
'post': post,
}
return render(request, 'project_name/post.html', context)
I hope I have explained what I'd like to do. Django is new to me and querysets are still a bit complex.
Shouldn't you try adding galleriesto posts from posts?
#Edit ___ @TwinDewey In this case you need to make a query in Views to get the Galleries when showing Post details.
Or you can make a query and merge it with the Post context using
That´s for gallery. Posts would have another query.