Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
iPPIDB
ippidb-web
Commits
9b275b48
Commit
9b275b48
authored
Jun 29, 2020
by
Hervé MENAGER
Browse files
Use django-polymorphic to manage ProteinDomainComplex subclasses
WIP on #225
parent
f2265631
Changes
5
Hide whitespace changes
Inline
Side-by-side
ippisite/ippidb/migrations/0064_proteindomaincomplex_polymorphic_ctype.py
0 → 100644
View file @
9b275b48
# 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
),
]
ippisite/ippidb/models.py
View file @
9b275b48
...
...
@@ -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
(
Polymorphic
Model
):
"""
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"
...
...
ippisite/ippisite/settings.py
View file @
9b275b48
...
...
@@ -57,6 +57,7 @@ INSTALLED_APPS = [
"allauth.socialaccount"
,
# "allauth.socialaccount.providers.github",
"allauth.socialaccount.providers.orcid"
,
"polymorphic"
,
]
MIDDLEWARE
=
[
...
...
ippisite/ippisite/settings.template.py
View file @
9b275b48
...
...
@@ -60,6 +60,7 @@ INSTALLED_APPS = [
"allauth.socialaccount"
,
# "allauth.socialaccount.providers.github",
"allauth.socialaccount.providers.orcid"
,
"polymorphic"
,
]
MIDDLEWARE
=
[
...
...
ippisite/requirements-core.txt
View file @
9b275b48
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment