#coding=utf-8 from django.db import models from apps.exceptions import CustomError class OptionManager(models.Manager): def _get_instance_by_type_and_id(self, type, id): instance = self.model.objects.filter(type=type, id=id).first() if not instance: raise CustomError( u'请从下拉列表中选择{0}。
如果{0}不在下拉列表中,请到“系统设置”-->“自定义项”添加。'.format( self.model.TYPE_CHOICES[type][1] ) ) return instance