title: Save the Celery task in DB- Django
body: <p>I'm referring to <a href="http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html" rel="nofollow noreferrer">Django Celery</a> documents. </p>
  
  <p>I created <code>celery.py</code> in my <code>proj/proj</code> just as the document said. and then included <code>__init__.py</code></p>
  
  <p><strong>celery.py</strong></p>
  
  <pre><code>from __future__ import absolute_import
  import os
  from celery import Celery
  from django.conf import settings
  
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')
  app = Celery('proj')
  app.conf.update(
      CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
  )
  app.config_from_object('django.conf:settings')
  app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
  </code></pre>
  
  <p><strong>__init__.py</strong></p>
  
  <pre><code>from __future__ import absolute_import
  from .celery import app as celery_app
  </code></pre>
  
  <p>I installed <code>pip install django-celery</code> , then migrated <code>python manage.py migrate djcelery</code>
  It made some of the tables in my DB.</p>
  
  <p><strong>tasks.py</strong></p>
  
  <pre><code>from __future__ import absolute_import
  from celery import shared_task
  import requests
  import json
  
  @shared_task
  def post_notification(data,url):
      headers = {'content-type': 'application/json'}
      requests.post(url, data=json.dumps(data), headers=headers)
  </code></pre>
  
  <p>After that I called my task in my views as </p>
  
  <pre><code>task = post_notification.delay(data,url)
  print task.id #it prints an id
  print task.status # prints PENDING
  </code></pre>
  
  <p>But nothing gets logged into any of my tables. </p>
  
  <p>I've read my threads on SO,<a href="https://stackoverflow.com/questions/16633107/celery-django-how-to-write-task-state-to-database?rq=1">Thread1</a>  , <a href="https://stackoverflow.com/questions/10672987/how-to-properly-configure-djcelery-results-backend-to-database">Thread2</a> and many more given on these threads, but nothing happens.</p>
  
  <p><strong>It provides me the ID &amp; status of the task but how do I save the task in the DB?</strong> Usually it should get logged into <code>celery_taskmeta</code>, but there's nothing in there.</p>
  
  <p>Though the task gets execute but I want to save the task in  DB as well. How can I do it? Is there something I'm missing?</p>