How to do it...

  1. Open the models.py file from this package in your favorite editor, and add the following content:
# utils/models.pyfrom enum import Enumfrom functools import reducefrom django.db import modelsfrom django.utils.translation import ugettext_lazy as _class ChoiceEnum(Enum):    @classmethod    def choices(cls):        return tuple((x.name, x.value) for x in cls)class ItemPropChoiceEnum(ChoiceEnum):    @classmethod    def choices(cls, scope=None):        sources = [cls] + cls.parents()        choices = reduce((lambda x, y: tuple(set(x) | set(y))),                         sources)        if scope:            choices = tuple(set(choices) & set(scope.choices()))        return choices    @classmethod    def parents(cls):        return []class ItemType(ChoiceEnum):    THING = "Thing"    CREATIVE_WORK = "CreativeWork" BOOK = "Book" ...

Get Django 2 Web Development Cookbook - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.