D
D
Dennis2016-05-17 21:06:53
Django
Dennis, 2016-05-17 21:06:53

Django - load multiple photos at once?

Good afternoon!

models.py

class Location(models.Model):
        user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1)
        name = models.CharField(max_length=100, verbose_name="Локация", default=u'')
        photos = models.ImageField(upload_to='photos', null=True)

forms.py

class LocationForm(forms.ModelForm):

    class Meta:
        model = Location
        fields = ['name', 'photos']

views.py

    class AddLocationPageView(FormView):
        template_name = 'add_location.html'
        form_class = LocationForm
    
        def form_valid(self, form):
            form.save()
            return super(AddLocationPageView, self).form_valid(form)

I need to be able to upload multiple photos at once.
How to do it?
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Sergeev, 2016-05-18
@SergeevAI

You make a separate model for photos and connect it to location via m2m field.

Z
zelsky, 2016-05-18
@zelsky

formset google

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question