Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

[Django] Multiple images/gallery to models

How can I add a field to models that will upload more than one image? The default models.ImageField() can only take more image. I've been trying to search through the docs, but if I don't know what I'm looking for, it is trying to find a needle in a haystack.

2 Answers

Benjamin Lange
Benjamin Lange
16,178 Points

There isn't a multiple image field in Django. The easiest way to allow multiple images would be to add another class to store the images and then add a ForeignKey field to match the image to the original class.

Do you have a link to some "documentation" or tutorial for this? Maybe a YouTube videos. I had a little trouble picturing it in my head.

Benjamin Lange
Benjamin Lange
16,178 Points

Take a look at this StackOverflow question. It covers setting up the models, the forms, the views, and the templates. I hope that helps!