Last active
December 25, 2019 12:36
-
-
Save maxpoletaev/4f188374a0daba54302fd406a58a590e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AlbumAdminForm(forms.ModelForm): | |
photos_batch = forms.FileField( | |
widget=forms.FileInput(attrs={ | |
'accept': 'image/png, image/jpeg', | |
'multiple': True, | |
}), | |
required=False, | |
label='Photos', | |
help_text='Choose multiple files.', | |
) | |
class Meta: | |
model = Album | |
fields = '__all__' | |
@admin.register(Album) | |
class AlbumAdmin(admin.ModelAdmin): | |
form = AlbumAdminForm | |
def save_related(self, request, form, formsets, change): | |
super().save_related(request, form, formsets, change) | |
photos_batch = request.FILES.getlist('photos_batch') | |
for photo in photos_batch: | |
form.instance.photos.create(image=photo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment