# Generated by Django 3.2.23 on 2024-01-19 22:38

from django.db import migrations, models
import json

def populate_cameraconfig(apps, schema_editor):
    GlobalConfig = apps.get_model('products', 'GlobalConfig')
    CameraConfig = apps.get_model('products', 'CameraConfig')

    rules = GlobalConfig.objects.filter(name='camera-zoom').first()
    print("rules:", rules)
    if rules:
        for r in json.loads(rules.value):
            print(r)
            CameraConfig.objects.create(
                name=r['model'],
                model_text=r['model'],
                zoom=r['zoom'],
                use_web_view=r.get('web_view', False),
                )

def reverse_populate_cameraconfig(apps, schema_editor):
    pass

class Migration(migrations.Migration):

    dependencies = [
        ('products', '0080_cameraconfig_notes'),
    ]

    operations = [
        migrations.RunPython(populate_cameraconfig, reverse_populate_cameraconfig)
    ]
