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
Copy file name to clipboardExpand all lines: README.md
+24Lines changed: 24 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -219,6 +219,30 @@ The default processor is `pictures.tasks.process_picture`. It takes a single
219
219
argument, the `PictureFileFile` instance. You can use this to override the
220
220
processor, should you need to do some custom processing.
221
221
222
+
### Validators
223
+
224
+
The library ships with validators to restrain image dimensions:
225
+
226
+
```python
227
+
from django.db import models
228
+
from pictures.models import PictureField
229
+
from pictures.validators import MaxSizeValidator, MinSizeValidator
230
+
231
+
232
+
classProfile(models.Model):
233
+
picture = PictureField(
234
+
upload_to="avatars",
235
+
validators=[
236
+
MinSizeValidator(400, 300), # At least 400x300 pixels
237
+
MaxSizeValidator(4096, 4096), # At most 4096x4096 pixels
238
+
]
239
+
)
240
+
241
+
Use `None` to limit only one dimension: `MaxSizeValidator(2048, None)` limits only width.
242
+
243
+
> [!IMPORTANT]
244
+
> These validators check image dimensions, notfile size. Consider implementing HTTP request body size restrictions (e.g., in your web server or Django middleware) to prevent large file uploads.
245
+
222
246
## Migrations
223
247
224
248
Django doesn't support file field migrations, but we do.
0 commit comments