old_contents: # -*- coding: utf-8 -*-
  # Generated by Django 1.11.6 on 2017-12-24 06:44
  from __future__ import unicode_literals
  
  from django.db import migrations
  
  
  def create_classifications(apps, schema_editor):
      from ..models import Classification, PublicBody  # Use treebeard API
      # Classification = apps.get_model('publicbody', 'Classification')
      # PublicBody = apps.get_model('publicbody', 'PublicBody')
      classifications = {}
      for pb in PublicBody.objects.exclude(classification_slug=''):
          if pb.classification_slug in classifications:
              pb.classification = classifications[pb.classification_slug]
          else:
              root = Classification.add_root(
                  name=pb.classification_name,
                  slug=pb.classification_slug
              )
              pb.classification = root
              classifications[pb.classification_slug] = root
          pb.save()
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('publicbody', '0006_auto_20171224_0732'),
      ]
  
      operations = [
          migrations.RunPython(create_classifications),
      ]
  
new_contents: # -*- coding: utf-8 -*-
  # Generated by Django 1.11.6 on 2017-12-24 06:44
  from __future__ import unicode_literals
  
  from django.db import migrations
  
  
  def create_classifications(apps, schema_editor):
      from ..models import Classification  # Use treebeard API
      # Classification = apps.get_model('publicbody', 'Classification')
      PublicBody = apps.get_model('publicbody', 'PublicBody')
      classifications = {}
      for pb in PublicBody.objects.exclude(classification_slug=''):
          if pb.classification_slug in classifications:
              pb.classification = classifications[pb.classification_slug]
          else:
              root = Classification.add_root(
                  name=pb.classification_name,
                  slug=pb.classification_slug
              )
              pb.classification = root
              classifications[pb.classification_slug] = root
          pb.save()
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('publicbody', '0006_auto_20171224_0732'),
      ]
  
      operations = [
          migrations.RunPython(create_classifications),
      ]
  
subject: Use historic PublicBody in data migration