How to limit the image file size in image field in django admin panel (on client side)?

I am having few inline fields which have image field in them, what i'm trying to do is to determine the file size at the time of image selection, by selection I i would like to restrict the user before the request has been submitted. glimpse of my admin panel and I can do the file size check on the server using validators but in a few cases even before the validator can handle issue I got DATA_UPLOAD_MAX_MEMORY_SIZE exception, I do have enlarged the size , but still i could get that error that error of request body is exceeding max upload size.

here is my code for the menu image

class MenuImage(models.Model):
    """Salon Image Model"""
    class Meta:
        verbose_name = _("Menu Image")
        verbose_name_plural = _("Menu Images")

    salon = models.ForeignKey(
        Salon, on_delete=models.CASCADE, related_name='menu_images', null=True, blank=True)
    image = models.ImageField(upload_to='salon_images',
                              help_text="Dimensions should in 175 x 100 px")

    def __str__(self):
        return self.salon.full_name
    
    def save(self, *args, **kwargs):
        compressed_image = ImageResizing.custom_resizing_and_compress(self.image)
        self.image = compressed_image
        super().save(*args, **kwargs)

and this is how I am using it as an inline field

class SalonModelAdmin(DjangoObjectActions, admin.ModelAdmin):
    inlines = [OpeningHoursInline, GalleryInline,MenuImageInline,
               SalonBankDetailInline, SalonLegalDocumentInline, SalonContactInline]
    fields = ("full_name","contact_number","neighbourhood",
                "salon_location","explore","salon_service","home_services",
                "featured","categories","commission",
                "cover_image","transportation_cost",
                "home_service_order_limit","logo_image",
                "salon_description","preference","auto_booking",
                "trending", "disable",)
    list_display = ("salon", "featured", "home_services",
                    "contact_number", "commission",)
    search_fields = ['full_name']
    list_filter = ("featured", "trending", "home_services",
                   "full_name", "preference", "disable", 
                   "categories", 'neighbourhood', ExploreSalonForSalonModelFilter)
    actions = [export_salons_as_csv]

and currently in my settings I have randomly given large number

DATA_UPLOAD_MAX_MEMORY_SIZE = 9942880
Back to Top