class ModelBaseWithChoices(ModelBase):

    def __new__(cls, name, bases, attrs):

        def format_label(label):
            return re.sub('[^A-Z]+', '_', label.upper()).strip('_')

def get_choices(attrs):
    for attr, value in list(attrs.items()):
        if attr.endswith('_CHOICES') and isinstance(value, tuple):
            base = '_'.join(attr.split('_')[:-1])
for val, label in value:
    yield '_'.join((base, format_label(label))), val
attrs.update(list(get_choices(attrs)))
return super(ModelBaseWithChoices, cls).__new__(cls, name, bases, attrs)


class ModelWithChoices(models.Model, metaclass=ModelBaseWithChoices):
    pass


class Meta:
    abstract = True
Automatically add constants for each of the choices in a Django model