ytsm/app/YtManagerApp/migrations/0014_fix_video_provider.py

29 lines
793 B
Python

# Generated by Django 3.0.4 on 2020-04-10 20:37
from django.db import migrations, models
import json
def fix_video_provider(apps, schema_editor):
globalPrefs = apps.get_model('dynamic_preferences', 'GlobalPreferenceModel')
api_key_entries = globalPrefs.objects.filter(name='youtube_api_key')
if len(api_key_entries) < 1:
return
videoProviderConfig = apps.get_model('YtManagerApp', 'VideoProviderConfig')
ytApiProvider = videoProviderConfig(provider_id='YtAPI', settings=json.dumps({
'api_key': api_key_entries[0].raw_value
}))
ytApiProvider.save()
class Migration(migrations.Migration):
dependencies = [
('YtManagerApp', '0013_auto_20200410_2037'),
]
operations = [
migrations.RunPython(fix_video_provider)
]