File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323from core .validators import (
2424 image_validator ,
2525 large_file_max_size_validator ,
26+ downscale_image_file_size_validator ,
2627)
2728from core .templatetags .custom_static import large_static
2829
@@ -208,7 +209,7 @@ class User(BaseUser):
208209 upload_to = "profile-images" ,
209210 null = True ,
210211 blank = True ,
211- validators = [image_validator ],
212+ validators = [image_validator , downscale_image_file_size_validator ],
212213 )
213214 image_thumbnail = ImageSpecField (
214215 source = "profile_image" ,
Original file line number Diff line number Diff line change @@ -59,15 +59,15 @@ def test_user_model_image_file_size(user):
5959 Test that the `image` field rejects files larger than a specific size.
6060 """
6161 valid_image = SimpleUploadedFile (
62- "test.jpg" , b"a" * (1 * 1024 * 1024 - 1 ), content_type = "image/jpeg"
62+ "test.jpg" , b"a" * (5 * 1024 * 1024 - 1 ), content_type = "image/jpeg"
6363 )
6464 user .profile_image = valid_image
6565 # This should not raise any errors
6666 user .full_clean ()
6767
6868 # This should fail (just over 1MB)
6969 invalid_image = SimpleUploadedFile (
70- "too_large.jpg" , b"a" * (1 * 1024 * 1024 + 1 ), content_type = "image/jpeg"
70+ "too_large.jpg" , b"a" * (5 * 1024 * 1024 + 1 ), content_type = "image/jpeg"
7171 )
7272 user .profile_image = invalid_image
7373 # This should raise a ValidationError for file size
You can’t perform that action at this time.
0 commit comments