Skip to content

Commit

Permalink
Preferred alias can be changed by user
Browse files Browse the repository at this point in the history
attribute name in API is 'current_identifier'
  • Loading branch information
kaliif committed Oct 23, 2024
1 parent c2e600b commit 0769b5e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
19 changes: 19 additions & 0 deletions viewer/migrations/0081_alter_compound_current_identifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 3.2.25 on 2024-10-23 15:20

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


class Migration(migrations.Migration):

dependencies = [
('viewer', '0080_alter_compoundidentifier_compound'),
]

operations = [
migrations.AlterField(
model_name='compound',
name='current_identifier',
field=models.OneToOneField(blank=True, help_text='The preferred alias for this compound.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='viewer.compoundidentifier'),
),
]
2 changes: 1 addition & 1 deletion viewer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class Compound(models.Model):
inchi = models.TextField(unique=False, db_index=True)
smiles = models.CharField(max_length=255, db_index=True)
compound_code = models.TextField(null=True)
current_identifier = models.ForeignKey(
current_identifier = models.OneToOneField(
'CompoundIdentifier',
blank=True,
null=True,
Expand Down
20 changes: 20 additions & 0 deletions viewer/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,26 @@ class Meta:
"description",
"comments",
)
extra_kwargs = {
"id": {"read_only": True},
"inchi": {"read_only": True},
"smiles": {"read_only": True},
"current_identifier": {"read_only": False},
"all_identifiers": {"read_only": True},
"project_id": {"read_only": True},
"compound_code": {"read_only": True},
"inspirations": {"read_only": True},
"description": {"read_only": True},
"comments": {"read_only": True},
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Limit the queryset to only identifiers related to this compound
if self.instance:
self.fields[
'current_identifier'
].queryset = self.instance.all_identifiers.all()


class SiteObservationSerializer(serializers.ModelSerializer):
Expand Down
2 changes: 1 addition & 1 deletion viewer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def patch(self, request, pk):
)


class CompoundView(ISPyBSafeQuerySet):
class CompoundView(mixins.UpdateModelMixin, ISPyBSafeQuerySet):
"""Compounds (api/compounds)"""

queryset = models.Compound.filter_manager.filter_qs()
Expand Down

0 comments on commit 0769b5e

Please sign in to comment.