0

I have the following two models.

class Event(models.Model):
    title = models.CharField(max_length=120)
    ...

    def __str__(self):
        return self.title


class EventPhotos(models.Model):
    event = models.ForeignKey(Event, on_delete=models.CASCADE)
    photo = models.ImageField(upload_to='events/')

What I am trying to do is to use the default admin panel to select multiple images for upload.

My current code works as I want it to, I create an event then open the EventPhotos model, select the event I just created and I have the select file button which I can use to add photos, but the thing is, Django lets me add only 1 photo! I want to add multiple photos.

Thanks in advance guys, would appreciate it if you help me out.

Amin
  • 2,605
  • 2
  • 7
  • 15

2 Answers2

1

As per what I understand you are looking for a way to implement many to one relationship. A similar question has been answered here before, you can have a look at Multiple images per Model

Srishti Ahuja
  • 181
  • 1
  • 7
1

Your admin.py file should be like:

class EventPhotosInline(admin.StackedInline):
    model = EventPhotos

@admin.register(Event)
class EventAdmin(admin.ModelAdmin):
    inlines = [EventPhotosInline,]

Amin
  • 2,605
  • 2
  • 7
  • 15