Skip to content

Commit 67a476b

Browse files
committed
Add example to README
1 parent cafec7e commit 67a476b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,38 @@ The default processor is `pictures.tasks.process_picture`. It takes a single
227227
argument, the `PictureFileFile` instance. You can use this to override the
228228
processor, should you need to do some custom processing.
229229

230+
### Signals
231+
232+
The async image processing emits a signal when the task is complete.
233+
You can use that to store when the pictures have been processed,
234+
so that a placeholder could be rendered in the meantime.
235+
236+
```python
237+
# models.py
238+
from django.db import models
239+
from pictures.models import PictureField
240+
241+
242+
class Profile(models.Model):
243+
title = models.CharField(max_length=255)
244+
picture = PictureField(upload_to="avatars")
245+
picture_processed = models.BooleanField(editable=False, null=True)
246+
247+
248+
# signals.py
249+
from django.dispatch import receiver
250+
from pictures import signals
251+
252+
from .models import Profile
253+
254+
255+
@receiver(signals.picture_processed, sender=Profile._meta.get_field("picture"))
256+
def picture_processed_handler(*, sender, file_name, **__):
257+
sender.model.objects.filter(**{sender.name: file_name}).update(
258+
picture_processed=True
259+
)
260+
```
261+
230262
### Validators
231263

232264
The library ships with validators to restrain image dimensions:

0 commit comments

Comments
 (0)