from __future__ import unicode_literals

from django.db import migrations

from ovp_organizations.models import Organization

def add_members(apps, schema_editor):
  for organization in Organization.objects.all():
    organization.members.add(organization.owner)


def remove_members(apps, schema_editor):
  for organization in Organization.objects.all():
    organization.members.clear()


class Migration(migrations.Migration):

    dependencies = [
        ('ovp_organizations', '0007_organization_members'),
    ]

    operations = [
        migrations.RunPython(add_members, reverse_code=remove_members)
    ]

from __future__ import unicode_literals

from django.db import migrations

from ovp_organizations.models import Organization

def add_members(apps, schema_editor):
  for organization in Organization.objects.only('pk', 'members').all():
    organization.members.add(organization.owner)


def remove_members(apps, schema_editor):
  for organization in Organization.objects.only('pk', 'members').all():
    organization.members.clear()


class Migration(migrations.Migration):

    dependencies = [
        ('ovp_organizations', '0007_organization_members'),
    ]

    operations = [
        migrations.RunPython(add_members, reverse_code=remove_members)
    ]

Add ".only" restriction to query on migration 0008
Add ".only" restriction to query on migration 0008

  from __future__ import unicode_literals
  
  from django.db import migrations
  
  from ovp_organizations.models import Organization
  
  def add_members(apps, schema_editor):
-   for organization in Organization.objects.all():
+   for organization in Organization.objects.only('pk', 'members').all():
      organization.members.add(organization.owner)
  
  
  def remove_members(apps, schema_editor):
-   for organization in Organization.objects.all():
+   for organization in Organization.objects.only('pk', 'members').all():
      organization.members.clear()
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('ovp_organizations', '0007_organization_members'),
      ]
  
      operations = [
          migrations.RunPython(add_members, reverse_code=remove_members)
      ]
  
Add ".only" restriction to query on migration 0008
## Code Before:
from __future__ import unicode_literals

from django.db import migrations

from ovp_organizations.models import Organization

def add_members(apps, schema_editor):
  for organization in Organization.objects.all():
    organization.members.add(organization.owner)


def remove_members(apps, schema_editor):
  for organization in Organization.objects.all():
    organization.members.clear()


class Migration(migrations.Migration):

    dependencies = [
        ('ovp_organizations', '0007_organization_members'),
    ]

    operations = [
        migrations.RunPython(add_members, reverse_code=remove_members)
    ]

## Instruction:
Add ".only" restriction to query on migration 0008
## Code After:
from __future__ import unicode_literals

from django.db import migrations

from ovp_organizations.models import Organization

def add_members(apps, schema_editor):
  for organization in Organization.objects.only('pk', 'members').all():
    organization.members.add(organization.owner)


def remove_members(apps, schema_editor):
  for organization in Organization.objects.only('pk', 'members').all():
    organization.members.clear()


class Migration(migrations.Migration):

    dependencies = [
        ('ovp_organizations', '0007_organization_members'),
    ]

    operations = [
        migrations.RunPython(add_members, reverse_code=remove_members)
    ]
