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

34 lines
918 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):
try:
globalPrefs = apps.get_model('dynamic_preferences', 'GlobalPreferenceModel')
except LookupError as e:
print("Warning: could not get dynamic_preferences model.")
return
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)
]