Skip to content

Commit 08992d5

Browse files
committed
2 parents 692fbc3 + b6e8605 commit 08992d5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,36 @@
11
# PyMODM-ImageFileField
22
ImageFileField for PyMODM
3+
4+
```
5+
from os.path import join
6+
7+
from pymodm import MongoModel, fields
8+
from imagefilefield.fields import ImageFileField
9+
10+
class TestImage(MongoModel):
11+
IMAGE_SIZES = {
12+
"small": {"size": (200, 200)},
13+
"medium": {"size": (625, 625)},
14+
"default": {"size": (800, 800), "smartcrop": True}
15+
# if key `default`, other sizes will based this size
16+
# `smartcrop` will use image detection on crop
17+
}
18+
19+
text = fields.CharField()
20+
image = ImageFileField(
21+
upload_to=join(MEDIA_ROOT, "test_image/%Y/%m/%d/"),
22+
blank=True,
23+
media_url=join(MEDIA_URL, "test_image/%Y/%m/%d/"))
24+
# using custom size
25+
image2 = ImageFileField(
26+
upload_to=join(MEDIA_ROOT, "test_image/%Y/%m/%d/"),
27+
blank=True,
28+
image_sizes = {
29+
"small": {"size": (200, 100), "smartcrop": True},
30+
"medium": {"size": (525, 625), "smartcrop": True},
31+
"big": {"size": (700, 700), "smartcrop": True}
32+
}
33+
media_url=join(MEDIA_URL, "test_image/%Y/%m/%d/"))
34+
created = fields.DateTimeField(default=timezone.now)
35+
36+
```

0 commit comments

Comments
 (0)