Commit 1ea54601 authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

make Compound families a cached property to have it ready in qs

this is to FIX #168
parent 54aa4085
# Generated by Django 2.2.1 on 2019-12-19 14:19
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('ippidb', '0039_auto_20191216_1438'),
]
operations = [
migrations.AddField(
model_name='compound',
name='families',
field=models.TextField(blank=True, null=True, verbose_name='PPI family names'),
),
]
......@@ -714,6 +714,8 @@ class Compound(AutoFillableModel):
best_activity_ppi_family_name = models.CharField(
"Best activity PPI family name", max_length=30, null=True, blank=True
)
families = models.TextField("PPI family names", null=True, blank=True)
le = models.FloatField(verbose_name="Ligand efficiency", null=True, blank=True)
lle = models.FloatField(verbose_name="Lipophilic efficiency", null=True, blank=True)
lipinsky_mw = models.BooleanField("MW ok for Lipinsky", null=True, blank=True)
......@@ -875,13 +877,6 @@ class Compound(AutoFillableModel):
.count()
)
@property
def families(self):
"""
return the all PPI families for PPIs involved in the compound activity of the compound
"""
return list(set([ca.ppi.family for ca in self.compoundaction_set.all()]))
@property
def sorted_similar_drugbank_compounds(self):
return self.drugbankcompoundtanimoto_set.order_by("-tanimoto")
......@@ -1283,6 +1278,9 @@ class Contribution(models.Model):
def update_compound_cached_properties():
for c in Compound.objects.all():
c.families = ', '.join(list(set([ca.ppi.family.name for ca in c.compoundaction_set.all()])))
c.save()
Compound.objects.update(
pubs=Subquery(
Compound.objects.filter(id=OuterRef("id"))
......
......@@ -40,7 +40,7 @@
<td scope="col">{{ compound.common_name|default_if_none:"-" }}</td>
{% endif %}
{% if "families" in fields %}
<td scope="col">{% for family in compound.families %}{{ family.name }}{% if not forloop.last %}, {% endif %}{% endfor %}</td>
<td scope="col">{{ compound.families }}</td>
{% endif %}
{% if "pubs" in fields %}
<td scope="col">{{ compound.pubs }}</td>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment