# Generated by Django 3.1 on 2020-11-16 14:31

from django.db import migrations

def add_default_search_term(apps, schema_editor):
    search_term = apps.get_model('partisan', 'search_term')
    term = search_term(term='election')
    term.save()
    tweets = apps.get_model('partisan', 'tweet')
    tweet_list = tweets.objects.all()
    for tweet in tweet_list:
        tweet.term = term
        tweet.save()

def revert_default_search_term(apps, schema_editor):
    tweets = apps.get_model('partisan', 'tweet')
    tweet_list = tweets.objects.all()
    for tweet in tweet_list:
        tweet.term = None
        tweet.save()
    search_term = apps.get_model('partisan', 'search_term')
    search_term = search_term.objects.filter(id=0).delete()

class Migration(migrations.Migration):

    dependencies = [
        ('partisan', '0010_auto_20201116_0631'),
    ]

    operations = [
        migrations.RunPython(add_default_search_term, revert_default_search_term)
    ]
