0008_remove_task_watchers.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from django.db import connection
  4. from django.db import models, migrations
  5. from django.contrib.contenttypes.models import ContentType
  6. from django.contrib.contenttypes.management import update_all_contenttypes
  7. def create_notifications(apps, schema_editor):
  8. update_all_contenttypes()
  9. sql="""
  10. INSERT INTO notifications_watched (object_id, created_date, content_type_id, user_id, project_id)
  11. SELECT task_id AS object_id, now() AS created_date, {content_type_id} AS content_type_id, user_id, project_id
  12. FROM tasks_task_watchers INNER JOIN tasks_task ON tasks_task_watchers.task_id = tasks_task.id""".format(content_type_id=ContentType.objects.get(model='task').id)
  13. cursor = connection.cursor()
  14. cursor.execute(sql)
  15. class Migration(migrations.Migration):
  16. dependencies = [
  17. ('notifications', '0004_watched'),
  18. ('tasks', '0007_auto_20150629_1556'),
  19. ]
  20. operations = [
  21. migrations.RunPython(create_notifications),
  22. migrations.RemoveField(
  23. model_name='task',
  24. name='watchers',
  25. ),
  26. ]