Skip to content

Instantly share code, notes, and snippets.

@teror4uks
Last active January 28, 2018 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teror4uks/5483fcd54455f2e6a73a5db1d1e58272 to your computer and use it in GitHub Desktop.
Save teror4uks/5483fcd54455f2e6a73a5db1d1e58272 to your computer and use it in GitHub Desktop.
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
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