Other bioinformatics software developers may be interested in solving this problem, so I post here my approach proposed by Alasdair .
The goal is to create a model for living species, for simplicity, say, an animal, and create an endpoint with the Django REST Framework representing the correct taxonomic ranks.
models.py
from django.db import models class Animal(models.Model): canonical_name = models.CharField(max_length=100, unique=True) species = models.CharField(max_length=60, unique=True) genus = models.CharField(max_length=30) family = models.CharField(max_length=30) order = models.CharField(max_length=30)
serializers.py
from collections import OrderedDict from rest_framework import serializers from .models import Species class SpeciesSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Animal fields = ('url', 'id', 'canonical_name', 'species', 'genus', 'subfamily', 'family', 'order', 'class_name', 'phylum') def to_representation(self, obj):
The to_representation method helps us manage the result. I added extra work to get taxonomic ranks in the desired order.
Thus, for red fox, the result is as follows:
Red fox (vulva vulva)
{ "url": "http://localhost:8000/animal/1", "id": 1, "canonical_name": "Red fox", "species": "Vulpes vulpes", "genus": "Vulpes", "family": "Canidae", "order": "Carnivora", "class": "Mammalia", "phylum": "Chordata" }
This is a simplified example, and in fact you will have many fields, or perhaps a model for each taxonomic rank, but somewhere you might run into a conflict between the reserved word class and the taxonomic rank of class .
Hope this helps other people as well.