old_contents: # Generated by Django 2.0.2 on 2018-02-11 20:03
  
  from django.db import migrations
  
  import logging
  log = logging.getLogger('importer')
  
  
  def data_migration(apps, schema_editor):
      Officer = apps.get_model('api', 'Officer')
      Group = apps.get_model('api', 'Group')
      officers = Officer.objects.exclude(
          group__kind=Group.KIND.quartet,
      )
      for officer in officers:
          try:
              officer.group = officer.organization.groups.get(status__gt=0)
          except Group.DoesNotExist as e:
              log.error("{} {}".format(e, officer.organization))
              officer.group = None
          except Group.MultipleObjectsReturned as e:
              log.error("{} {}".format(e, officer.organization))
              officer.group = None
          officer.save()
      officers = Officer.objects.filter(
          group__kind=Group.KIND.quartet,
      )
      for officer in officers:
          officer.group = officer.organization.groups.first()
          officer.save()
      return
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('api', '0069_auto_20180211_1110'),
      ]
  
      operations = [
          migrations.RunPython(data_migration),
      ]
  
new_contents: # Generated by Django 2.0.2 on 2018-02-11 20:03
  
  from django.db import migrations
  
  import logging
  log = logging.getLogger('importer')
  
  
  def data_migration(apps, schema_editor):
      Officer = apps.get_model('api', 'Officer')
      Group = apps.get_model('api', 'Group')
      officers = Officer.objects.exclude(
          group__kind=41,
      )
      for officer in officers:
          try:
              officer.group = officer.organization.groups.get(status__gt=0)
          except Group.DoesNotExist as e:
              log.error("{} {}".format(e, officer.organization))
              officer.group = None
          except Group.MultipleObjectsReturned as e:
              log.error("{} {}".format(e, officer.organization))
              officer.group = None
          officer.save()
      officers = Officer.objects.filter(
          group__kind=41,
      )
      for officer in officers:
          officer.group = officer.organization.groups.first()
          officer.save()
      return
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('api', '0069_auto_20180211_1110'),
      ]
  
      operations = [
          migrations.RunPython(data_migration),
      ]
  
subject: Fix migration