from __future__ import unicode_literals

from django.db import migrations
from django.utils.text import slugify


def create_slugs(apps, schema_editor):
    Value = apps.get_model('product', 'AttributeChoiceValue')
    for value in Value.objects.all():
        value.slug = slugify(value.display)
        value.save()


class Migration(migrations.Migration):

    dependencies = [
        ('product', '0017_attributechoicevalue_slug'),
    ]

    operations = [
        migrations.RunPython(create_slugs),
    ]

from __future__ import unicode_literals

from django.db import migrations
from django.utils.text import slugify


def create_slugs(apps, schema_editor):
    Value = apps.get_model('product', 'AttributeChoiceValue')
    for value in Value.objects.all():
        value.slug = slugify(value.display)
        value.save()


class Migration(migrations.Migration):

    dependencies = [
        ('product', '0017_attributechoicevalue_slug'),
    ]

    operations = [
        migrations.RunPython(create_slugs, migrations.RunPython.noop),
    ]

Allow to revert data migaration
Allow to revert data migaration

  from __future__ import unicode_literals
  
  from django.db import migrations
  from django.utils.text import slugify
  
  
  def create_slugs(apps, schema_editor):
      Value = apps.get_model('product', 'AttributeChoiceValue')
      for value in Value.objects.all():
          value.slug = slugify(value.display)
          value.save()
  
  
  class Migration(migrations.Migration):
  
      dependencies = [
          ('product', '0017_attributechoicevalue_slug'),
      ]
  
      operations = [
-         migrations.RunPython(create_slugs),
+         migrations.RunPython(create_slugs, migrations.RunPython.noop),
      ]
  
Allow to revert data migaration
## Code Before:
from __future__ import unicode_literals

from django.db import migrations
from django.utils.text import slugify


def create_slugs(apps, schema_editor):
    Value = apps.get_model('product', 'AttributeChoiceValue')
    for value in Value.objects.all():
        value.slug = slugify(value.display)
        value.save()


class Migration(migrations.Migration):

    dependencies = [
        ('product', '0017_attributechoicevalue_slug'),
    ]

    operations = [
        migrations.RunPython(create_slugs),
    ]

## Instruction:
Allow to revert data migaration
## Code After:
from __future__ import unicode_literals

from django.db import migrations
from django.utils.text import slugify


def create_slugs(apps, schema_editor):
    Value = apps.get_model('product', 'AttributeChoiceValue')
    for value in Value.objects.all():
        value.slug = slugify(value.display)
        value.save()


class Migration(migrations.Migration):

    dependencies = [
        ('product', '0017_attributechoicevalue_slug'),
    ]

    operations = [
        migrations.RunPython(create_slugs, migrations.RunPython.noop),
    ]
