0002_team_members_new.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Generated by Django 3.0.7 on 2020-06-13 21:47
  2. import logging
  3. from django.db import migrations, models
  4. from django.db.utils import IntegrityError
  5. logger = logging.getLogger(__name__)
  6. def move_members(apps, schema_editor):
  7. Team = apps.get_model("teams", "Team")
  8. for team in Team.objects.all():
  9. for member in team.members.all():
  10. org_user = team.organization.organization_users.filter(user=member).first()
  11. try:
  12. team.members_new.add(org_user)
  13. except IntegrityError:
  14. logger.warning("Unable to add team member %s", org_user)
  15. class Migration(migrations.Migration):
  16. dependencies = [
  17. (
  18. "organizations_ext",
  19. "0001_squashed_0003_alter_organization_id_alter_organization_users_and_more",
  20. ),
  21. ("teams", "0001_initial"),
  22. ]
  23. operations = [
  24. migrations.AddField(
  25. model_name="team",
  26. name="members_new",
  27. field=models.ManyToManyField(to="organizations_ext.OrganizationUser"),
  28. ),
  29. migrations.RunPython(move_members),
  30. ]