25👍
✅
Celery need to serialize the arguments for a task. Here, user
is not serializable, but you can replace it with its ID:
In tasks.py:
from __future__ import absolute_import
from celery.decorators import task
from django.contrib.auth import get_user_model
@task()
def user_send_activation_email(user_id):
user = get_user_model().objects.get(pk=user_id)
user.send_activation_email()
Then call it from views.py using:
user_send_activation_email.delay(user_id=user.pk)
8👍
see setting-task_serializer, you can set CELERY_TASK_SERIALIZER = ‘pickle’ in celery conf.
- Where do I modify the admin view code for a 3rd party app?
- Soft deleting objects in django
- How do I save data from a ModelForm to database in django?
- Making Twitter, Tastypie, Django, XAuth and iOS work to Build Django-based Access Permissions
Source:stackexchange.com