1๐
โ
You can create a mapping/dictionary that maps a model class to the values of each Enum
member, and use it in your _internal_method
for fetching the model class given the Enum
name:
class AbstractView(APIView):
models_map = {1: ConcreteModelOne, 2: ConcreteModelTwo}
def __init__(self):
#Init code here
def _internal_method(self, django_model, this_type=BazType.FOO):
record, created = self.models_map[this_type].objects.get_or_create(some_field = django_model)
๐คMoses Koledoye
Source:stackexchange.com