# Path: apps/taxonomy/models.py
# class TaxonRank(models.Model):
#     abbreviation = models.CharField(max_length=255)
#     zoology_rank = models.CharField(max_length=255)
#     botany_rank = models.CharField(max_length=255)
#     bacteria_rank = models.CharField(max_length=255)
#     prefix = models.CharField(max_length=255)
#     suffix = models.CharField(max_length=255)
# 
#     def __unicode__(self):
#         return u"%s" % (self.abbreviation)


import ast
from rest_framework import serializers
from rest_framework.reverse import reverse
from apps.taxonomy.models import TaxonRank



class TaxonRankListField(serializers.WritableField):

    def to_native(self, ranks):
        if ranks:
            rank_list = []
            for rank_id in ranks.split(';'):
                try:
                    rank = TaxonRank.objects.get(pk=rank_id)

# Path: apps/taxonomy/models.py
# class TaxonRank(models.Model):
#     abbreviation = models.CharField(max_length=255)
#     zoology_rank = models.CharField(max_length=255)
#     botany_rank = models.CharField(max_length=255)
#     bacteria_rank = models.CharField(max_length=255)
#     prefix = models.CharField(max_length=255)
#     suffix = models.CharField(max_length=255)
# 
#     def __unicode__(self):
#         return u"%s" % (self.abbreviation)


# Path: apps/taxonomy/fields/taxon_rank_list_field.py
import ast
from rest_framework import serializers
from rest_framework.reverse import reverse
from apps.taxonomy.models import TaxonRank




class TaxonRankListField(serializers.WritableField):

    def to_native(self, ranks):
        if ranks:
            rank_list = []
            for rank_id in ranks.split(';'):
                try:
                    rank = TaxonRank.objects.get(pk=rank_id)

                except (TaxonRank.DoesNotExist, ValueError):