Add multiple cards.
[audio.git] / src / youtube / migrations / 0006_move_cards.py
1 # Generated by Django 3.0.4 on 2020-05-15 16:34
2
3 from django.db import migrations
4
5
6 def move_cards(apps, schema_editor):
7     YouTube = apps.get_model('youtube', 'YouTube')
8     Card = apps.get_model('youtube', 'Card')
9     for yt in YouTube.objects.all():
10         if yt.intro_card:
11             Card.objects.create(
12                 youtube=yt,
13                 image=yt.intro_card,
14                 duration=yt.intro_card_duration or 0,
15                 order=-1
16             )
17         if yt.outro_card:            
18             Card.objects.create(
19                 youtube=yt,
20                 image=yt.outro_card,
21                 duration=yt.outro_card_duration or 0,
22                 order=1
23             )
24         yt.save()
25
26
27 class Migration(migrations.Migration):
28
29     dependencies = [
30         ('youtube', '0005_auto_20200515_1634'),
31     ]
32
33     operations = [
34         migrations.RunPython(
35             move_cards,
36             migrations.RunPython.noop,
37         )
38     ]