Last active
January 28, 2018 17:23
-
-
Save teror4uks/5483fcd54455f2e6a73a5db1d1e58272 to your computer and use it in GitHub Desktop.
Celery async call from guide http://oddbird.net/2017/03/20/serializing-things/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeMixin: | |
# Assuming that you want to trigger the task on save: | |
def save(self, *args, **kwargs): | |
ret = super().save(*args, **kwargs) | |
some_task.apply_async(( | |
self.__class__.__name__, | |
self.pk, | |
)) | |
return ret |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.apps import apps | |
@task() | |
def some_task(model_name, model_id): | |
Model = apps.get_model('django_app_name.{}'.format(model_name)) | |
obj = Model.objects.get(pk=model_id) | |
# Operate on obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment