Commit 8e08ff30 authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion
Browse files

Automatically build hiearchy on GET retrieve

parent da536d6d
Pipeline #17539 failed with stages
in 2 minutes and 15 seconds
from rest_framework.response import Response
from metagenedb.api.catalog.filters import TaxonomyFilter
from metagenedb.apps.catalog.models import Taxonomy
from metagenedb.apps.catalog.serializers import TaxonomySerializer
......@@ -10,3 +12,9 @@ class TaxonomyViewSet(BulkViewSet):
serializer_class = TaxonomySerializer
lookup_field = 'tax_id'
filterset_class = TaxonomyFilter
def retrieve(self, request, *args, **kwargs):
instance = self.get_object()
serializer = self.get_serializer(instance)
return Response(
......@@ -100,9 +100,11 @@ class Taxonomy(models.Model):
def build_parental_hierarchy(self):
hierarchy = {}
if != 'root' and self.parent is not None:
hierarchy[self.rank] = self.tax_id
hierarchy[self.rank] = self
hierarchy = {**hierarchy, **self.parent.build_parental_hierarchy()}
hierarchy['tax_id'] = self.tax_id
for level, value in hierarchy.items():
setattr(self, level, value)
return hierarchy
class Meta:
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