Skip to content
Snippets Groups Projects
Commit 9b275b48 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

Use django-polymorphic to manage ProteinDomainComplex subclasses

WIP on #225
parent f2265631
No related branches found
No related tags found
No related merge requests found
# 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),
]
......@@ -20,6 +20,7 @@ from django.utils.translation import ugettext_lazy as _
from django_celery_results.models import TaskResult
from django.dispatch import receiver
from django.db.models.signals import post_save
from polymorphic.models import PolymorphicModel
from .utils import FingerPrinter, smi2inchi, smi2inchikey
from .ws import (
......@@ -363,7 +364,7 @@ class ProteinDomainComplexGroup(models.Model):
return str(self)
class ProteinDomainComplex(models.Model):
class ProteinDomainComplex(PolymorphicModel):
"""
Protein-Domain association
"""
......@@ -405,6 +406,10 @@ class ProteinDomainBoundComplex(ProteinDomainComplex):
ppp_copy_nb_per_p = models.IntegerField(_("ppp_copy_nb_per_p"))
@property
def complex_type(self):
return "Bound"
class Meta:
verbose_name_plural = "bound complexes"
......@@ -427,6 +432,10 @@ class ProteinDomainPartnerComplex(ProteinDomainComplex):
Protein-Domain association with a "partner complex" role
"""
@property
def complex_type(self):
return "Partner"
class Meta:
verbose_name_plural = "partner complexes"
......
......@@ -57,6 +57,7 @@ INSTALLED_APPS = [
"allauth.socialaccount",
# "allauth.socialaccount.providers.github",
"allauth.socialaccount.providers.orcid",
"polymorphic",
]
MIDDLEWARE = [
......
......@@ -60,6 +60,7 @@ INSTALLED_APPS = [
"allauth.socialaccount",
# "allauth.socialaccount.providers.github",
"allauth.socialaccount.providers.orcid",
"polymorphic",
]
MIDDLEWARE = [
......
......@@ -28,3 +28,4 @@ git+https://gitlab.pasteur.fr/hmenager/django-diu.git#egg=django_diu
#openbabel
django-crispy-forms
celery
django-polymorphic
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment