from django.db import migrations

def create_initial_categories(apps, schema_editor):
    Category = apps.get_model('content', 'Category')
    default_categories = [
        {'name': 'General', 'slug': 'general'},
        {'name': 'Technology', 'slug': 'technology'},
        {'name': 'Science', 'slug': 'science'},
        {'name': 'Programming', 'slug': 'programming'},
        {'name': 'News', 'slug': 'news'},
    ]
    
    for category in default_categories:
        Category.objects.get_or_create(
            name=category['name'],
            slug=category['slug']
        )

def remove_initial_categories(apps, schema_editor):
    Category = apps.get_model('content', 'Category')
    Category.objects.filter(slug__in=['general', 'technology', 'science', 'programming', 'news']).delete()

class Migration(migrations.Migration):
    dependencies = [
        ('content', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(create_initial_categories, remove_initial_categories),
    ] 