You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Spam(models.Model)
pass
class Image(models.Model):
spam = models.ForeignKey(Spam)
image = models.ImageField()
I now want to add several images to Spam in admin. Plain Django suggests me to use StackInline, but I can't use multiupload here. Here is good recipe you can add to manual
class SpamForm(ModelForm):
additional_images = MultiFileField(min_num=1, max_num=3,required=False)
class Meta:
model = models.Event
fields = "__all__"
def save(self, commit=True): # It may be better to do that in save_m2m for newly created objects
save = super().save(commit)
for image in self.cleaned_data["additional_images"]:
saved_image = models.Image(event=save, additional_image=image)
saved_image.save()
save.additional_images.add(saved_image)
return save
class ImageAdmin(admin.StackedInline):
model = models.Image
@admin.register(models.Spam)
class EventAdmin(admin.ModelAdmin):
form = SpamForm
inlines = [ImageAdmin]
I now can add several images at once using separate form field:)
The text was updated successfully, but these errors were encountered:
Hello.
I have the following layout
I now want to add several images to
Spam
in admin. Plain Django suggests me to useStackInline
, but I can't use multiupload here. Here is good recipe you can add to manualI now can add several images at once using separate form field:)
The text was updated successfully, but these errors were encountered: