0064_proteindomaincomplex_polymorphic_ctype.py 1.57 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Generated by Django 2.2.1 on 2020-06-29 06:51

from django.db import migrations, models
import django.db.models.deletion



def forwards_func(apps, schema_editor):
    # add the content type to the classes using django-polymorphic
    # i.e. ProteinDomainBoundComplex and ProteinDomainPartnerComplex
    # code is adapted from https://django-polymorphic.readthedocs.io/en/stable/migrating.html
    ProteinDomainBoundComplex = apps.get_model('ippidb', 'ProteinDomainBoundComplex')
    ProteinDomainPartnerComplex = apps.get_model('ippidb', 'ProteinDomainPartnerComplex')
    ContentType = apps.get_model('contenttypes', 'ContentType')
    pdbc_ct = ContentType.objects.get_for_model(ProteinDomainBoundComplex)
    ProteinDomainBoundComplex.objects.filter(polymorphic_ctype__isnull=True).update(polymorphic_ctype=pdbc_ct)
    pdpc_ct = ContentType.objects.get_for_model(ProteinDomainPartnerComplex)
    ProteinDomainPartnerComplex.objects.filter(polymorphic_ctype__isnull=True).update(polymorphic_ctype=pdpc_ct)

class Migration(migrations.Migration):

    dependencies = [
        ('contenttypes', '0002_remove_content_type_name'),
        ('ippidb', '0063_fill_drugbank_links'),
    ]

    operations = [
        migrations.AddField(
            model_name='proteindomaincomplex',
            name='polymorphic_ctype',
            field=models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='polymorphic_ippidb.proteindomaincomplex_set+', to='contenttypes.ContentType'),
        ),
        migrations.RunPython(forwards_func, migrations.RunPython.noop),
    ]