0002_team_members_new.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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. ("organizations_ext", "0005_remove_organization_throttling_cycle_anchor"),
  18. ("teams", "0001_initial"),
  19. ]
  20. operations = [
  21. migrations.AddField(
  22. model_name="team",
  23. name="members_new",
  24. field=models.ManyToManyField(to="organizations_ext.OrganizationUser"),
  25. ),
  26. migrations.RunPython(move_members),
  27. ]