0003_auto_20141210_1108.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from django.db import models, migrations
  4. from django.db import connection
  5. from taiga.projects.userstories.models import *
  6. from taiga.projects.tasks.models import *
  7. from taiga.projects.issues.models import *
  8. from taiga.projects.models import *
  9. def _fix_tags_model(tags_model):
  10. table_name = tags_model._meta.db_table
  11. query = "select id from (select id, unnest(tags) tag from %s) x where tag LIKE '%%,%%'"%(table_name)
  12. cursor = connection.cursor()
  13. cursor.execute(query)
  14. for row in cursor.fetchall():
  15. id = row[0]
  16. instance = tags_model.objects.get(id=id)
  17. instance.tags = [tag.replace(",", "") for tag in instance.tags]
  18. instance.save()
  19. def fix_tags(apps, schema_editor):
  20. print("Fixing user issue tags")
  21. _fix_tags_model(Issue)
  22. class Migration(migrations.Migration):
  23. dependencies = [
  24. ('issues', '0002_issue_external_reference'),
  25. ]
  26. operations = [
  27. migrations.RunPython(fix_tags),
  28. ]