from __future__ import unicode_literals

from django.db import models, migrations


def migrate_avatar(apps, schema_editor):
    Avatar = apps.get_model("avatar", "Avatar")
    for avatar in Avatar.objects.filter(primary=True).all():
        avatar.user.picture = avatar.avatar
        avatar.user.save()
        avatar.save()


class Migration(migrations.Migration):
    dependencies = [
        ('users', '0006_user_picture'),
        ('avatar', '0001_initial')
    ]

    operations = [
        migrations.RunPython(migrate_avatar)

    ]

from __future__ import unicode_literals
from django.conf import settings
from django.db import models, migrations


if 'avatar' in settings.INSTALLED_APPS:
    def migrate_avatar(apps, schema_editor):
        Avatar = apps.get_model("avatar", "Avatar")
        for avatar in Avatar.objects.filter(primary=True).all():
            avatar.user.picture = avatar.avatar
            avatar.user.save()
            avatar.save()

    class Migration(migrations.Migration):
        dependencies = [
            ('users', '0006_user_picture'),
            ('avatar', '0001_initial')
        ]

        operations = [
            migrations.RunPython(migrate_avatar)

        ]
else:
    class Migration(migrations.Migration):
        dependencies = [('users', '0006_user_picture'), ]
        operations = []

Fix migrations after django-avatar drop
Fix migrations after django-avatar drop

  from __future__ import unicode_literals
- 
+ from django.conf import settings
  from django.db import models, migrations
  
  
+ if 'avatar' in settings.INSTALLED_APPS:
- def migrate_avatar(apps, schema_editor):
+     def migrate_avatar(apps, schema_editor):
-     Avatar = apps.get_model("avatar", "Avatar")
+         Avatar = apps.get_model("avatar", "Avatar")
-     for avatar in Avatar.objects.filter(primary=True).all():
+         for avatar in Avatar.objects.filter(primary=True).all():
-         avatar.user.picture = avatar.avatar
+             avatar.user.picture = avatar.avatar
-         avatar.user.save()
+             avatar.user.save()
-         avatar.save()
+             avatar.save()
  
+     class Migration(migrations.Migration):
+         dependencies = [
+             ('users', '0006_user_picture'),
+             ('avatar', '0001_initial')
+         ]
  
+         operations = [
+             migrations.RunPython(migrate_avatar)
- class Migration(migrations.Migration):
-     dependencies = [
-         ('users', '0006_user_picture'),
-         ('avatar', '0001_initial')
-     ]
  
+         ]
+ else:
+     class Migration(migrations.Migration):
+         dependencies = [('users', '0006_user_picture'), ]
-     operations = [
+         operations = []
-         migrations.RunPython(migrate_avatar)
  
-     ]
- 
Fix migrations after django-avatar drop
## Code Before:
from __future__ import unicode_literals

from django.db import models, migrations


def migrate_avatar(apps, schema_editor):
    Avatar = apps.get_model("avatar", "Avatar")
    for avatar in Avatar.objects.filter(primary=True).all():
        avatar.user.picture = avatar.avatar
        avatar.user.save()
        avatar.save()


class Migration(migrations.Migration):
    dependencies = [
        ('users', '0006_user_picture'),
        ('avatar', '0001_initial')
    ]

    operations = [
        migrations.RunPython(migrate_avatar)

    ]

## Instruction:
Fix migrations after django-avatar drop
## Code After:
from __future__ import unicode_literals
from django.conf import settings
from django.db import models, migrations


if 'avatar' in settings.INSTALLED_APPS:
    def migrate_avatar(apps, schema_editor):
        Avatar = apps.get_model("avatar", "Avatar")
        for avatar in Avatar.objects.filter(primary=True).all():
            avatar.user.picture = avatar.avatar
            avatar.user.save()
            avatar.save()

    class Migration(migrations.Migration):
        dependencies = [
            ('users', '0006_user_picture'),
            ('avatar', '0001_initial')
        ]

        operations = [
            migrations.RunPython(migrate_avatar)

        ]
else:
    class Migration(migrations.Migration):
        dependencies = [('users', '0006_user_picture'), ]
        operations = []
