from django.db.models import *
ordering = f"FIELD(`id`, {','.join([str(_) for _ in ids])})" # 默认就按照算法返回的 id 排序
p_data_result = PeptidesDataResult.objects.using("polypeptide").filter(id__in=ids).values().extra(select={'ordering': ordering}, order_by=('ordering',))
# 起别名
whens = [When(Q(reference__isnull=False) | ~Q(reference='') | Q(patent__isnull=False) | ~Q(patent=''), then=1)] # 计算是否 有文献
data = PeptidesDataResult.objects.using("polypeptide")\
.annotate(has_refer=Case(*whens, default=0))\