new_contents: # Generated by Django 2.1.2 on 2018-12-28 12:48
  
  from datetime import datetime, timezone
  
  from django.db import migrations
  
  
  def migrate_notes(apps, schema_editor):
      Site = apps.get_model('sites', 'Site')
      Comment = apps.get_model('django_comments', 'Comment')
      ContentType = apps.get_model('contenttypes', 'ContentType')
  
      # 1. import models
      Event = apps.get_model('workshops', 'Event')
      Person = apps.get_model('workshops', 'Person')
      Organization = apps.get_model('workshops', 'Organization')
      Membership = apps.get_model('workshops', 'Membership')
      TrainingRequest = apps.get_model('workshops', 'TrainingRequest')
      WorkshopRequest = apps.get_model('workshops', 'WorkshopRequest')
  
      # 2. find all objects with notes
      events = Event.objects.exclude(notes="")
      persons = Person.objects.exclude(notes="")
      organizations = Organization.objects.exclude(notes="")
      memberships = Membership.objects.exclude(notes="")
      trrequests = TrainingRequest.objects.exclude(notes="")
      wrequests = WorkshopRequest.objects.exclude(admin_comment="")
  
      # 3. content types for models above
      event_ct = ContentType.objects.get_for_model(Event)
      person_ct = ContentType.objects.get_for_model(Person)
      organization_ct = ContentType.objects.get_for_model(Organization)
      membership_ct = ContentType.objects.get_for_model(Membership)
      trrequest_ct = ContentType.objects.get_for_model(TrainingRequest)
      wrequest_ct = ContentType.objects.get_for_model(WorkshopRequest)
  
      # 3. prepare default data
      default_site = Site.objects.get_current()
      default_user = None
      default_user_name = 'Automatic comment'
      default_submit_date = datetime.now(timezone.utc)
  
      def comment_factory(content_type, object_pk, comment):
          return Comment(
              content_type=content_type,
              object_pk=object_pk,
              comment=comment,
              site=default_site,
              user=default_user,
              user_name=default_user_name,
              submit_date=default_submit_date,
          )
  
      comments = []
  
      # 4. create a comment object for each object with notes as comment content
      for event in events:
          comments.append(comment_factory(event_ct, event.pk, event.notes))
      for person in persons:
          comments.append(comment_factory(person_ct, person.pk, person.notes))
      for organization in organizations:
          comments.append(comment_factory(organization_ct, organization.pk,
                                          organization.notes))
      for membership in memberships:
          comments.append(comment_factory(membership_ct, membership.pk,
                                          membership.notes))
      for request in trrequests:
          comments.append(comment_factory(trrequest_ct, request.pk,
                                          request.notes))
      for request in wrequests:
          comments.append(comment_factory(wrequest_ct, request.pk,
                                          request.admin_comment))
  
      # 5. bulk add comments all at once
      Comment.objects.bulk_create(comments)
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('workshops', '0172_amy_sites'),
      ]
  
      operations = [
          migrations.RunPython(migrate_notes),
      ]
  
subject: Add migration for moving from model notes to comments