file page reorg
[audio.git] / src / youtube / migrations / 0016_populate_youtube_relations.py
1 # Generated by Django 3.1.2 on 2020-10-22 14:15
2
3 from django.db import migrations
4
5
6 def populate_youtube_relations(apps, schema_editor):
7     YouTube = apps.get_model('youtube', 'YouTube')
8     ThumbnailTemplate = apps.get_model('youtube', 'ThumbnailTemplate')
9     Project = apps.get_model('archive', 'Project')
10
11     try:
12         yt = YouTube.objects.first()
13     except YouTube.DoesNotExist:
14         yt = YouTube.objects.create(name='default')
15
16     Project.objects.filter(youtube=None).update(youtube=yt)
17     ThumbnailTemplate.objects.filter(youtube=None).update(youtube=yt)
18
19
20 class Migration(migrations.Migration):
21
22     dependencies = [
23         ('youtube', '0015_auto_20201022_1414'),
24         ('archive', '0019_auto_20201022_1414'),
25     ]
26
27     operations = [
28         migrations.RunPython(
29             populate_youtube_relations,
30             migrations.RunPython.noop
31         )
32     ]