I have registered a class like below to have an admin panel to upload images:
android_dashboard.register(Banner, BannerAdmin)
The banner model is as below:
class Banner(models.Model):
image = ImageField(
_('Image'), upload_to=upload_path, blank=True, null=True,
content_types=['image/jpg', 'image/jpeg', 'image/png'],
max_size=1 * 1024 * 1024, extensions=['jpg', 'jpeg', 'png']
)
type_of_banner = models.CharField(_('Type of Banner'), max_length=3, default='web')
class Meta:
verbose_name = _('Banner')
verbose_name_plural = _('Banners')
def __str__(self):
return '%s' % str(self.id)
And the model admin is like below:
class BannerAdmin(admin.ModelAdmin):
model = Banner
fields = ('image', 'type_of_banner')
list_display = ('image', 'type_of_banner')
For now when I login into admin section I can upload image directly to server. But I want to check ratio before uploading the image.
The question is how and when should I check the image width & height before uploading the image?