10

I am looking to create a portfolio using Django. I have tried using ImageField but it only allows me to upload and replace 1 photo.

I am new to Python and Django programming. How would I create a model to upload multiple images and show them in a gallery? Thanks.

Carl W.
  • 573
  • 3
  • 8
  • 13

5 Answers5

10

You can also use apps like photologue, imagekit, etc to simplify some of the tasks.

You may also upload multiple images using Model Formsets

machaku
  • 1,176
  • 8
  • 7
  • 2
    I have used photologue multiple times. Very easy to setup for a simple photography gallery and also good as a base from which to build a customized solution by subclassing. – AJJ Jun 23 '12 at 12:20
  • I just took a look at photologue and it could fit what I need. Thanks – Carl W. Jun 25 '12 at 02:18
2

Check out https://web.archive.org/web/20120621233904/http://lightbird.net/dbe/photo.html That will explain the basics.

If you want to add more then one pic through the admin you can do something like this:

class ChoiceInline(admin.StackedInline):
    model = Image # or what ever your models name is
    extra = 5 # or how ever many you want to add at a time

You should also go through the Django tutorial: https://docs.djangoproject.com/en/dev/intro/tutorial01/

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
lciamp
  • 675
  • 1
  • 9
  • 19
  • Thanks, I am looking through the lightbird tut. Should help a ton – Carl W. Jun 25 '12 at 02:19
  • This has been updated for newer versions of Django in the [portfolio app](http://lightbird.net/dbe2/portfolio.html#addimages-and-imageview) – rnevius Apr 15 '15 at 13:15
2

Just put the following code in your gallery template.

{% for image in images %}
                {% if forloop.first %}
                    <div class="row ">
                {% endif %}
                <div class="col-lg-4 col-md-4 col-12" >
                    <div class="text-center mt-2">
                        <img src="{{image.image.url}}"height="70%" width="70%" class="img-thumbnail" alt="...">
                    </div>
                </div>
                {% if forloop.counter|divisibleby:3 %}
                    </div>
                    <div class=row>
                {% endif %}
                {% if forloop.last %}
                        </div>
                {% endif %}
{% endfor %}
Muhammad Akram
  • 124
  • 2
  • 7
1

You can try django-galleryfield. BTW, I am the author of the package.

Dzhuang
  • 1,895
  • 1
  • 14
  • 15
0

Here's a tutorial that walks you through building an image gallery with Django using both the admin panel and using formsets if your web app has users who can't access the admin panel.

Royalbishop101
  • 179
  • 2
  • 9