I have my avatar in my UserProfile model in models.py file:-
class UserProfile(models.Model):
profileuser = models.OneToOneField(User)
handle = models.CharField(max_length=128, blank=True)
avatar = models.ImageField(upload_to='profile_images', blank=True)
In my forms.py file:-
class UserProfileForm(forms.ModelForm):
class Meta:
model= UserProfile
exclude= ('profileuser',)
In my views.py file , I am taking file data like below:-
if 'avatar' in request.FILES:
profile.avatar = request.FILES['avatar']
I want to limit max upload image file size to 1 MB. I have gone through many answers on stackoverflow. but still unable to do this. How can I make this happen?