I have been trying to use get_name_display() in my API View but it does not display the text, just number. I have checked the documentation but it does not mention anything about it - it should be working. May it have something to do with perform_update() method? For instance, the folowing code prints 3 instead of 'GaussianNB'.
Model
class Algorithm(models.Model):
ALGORITHM_NAME = (
(0, 'KNeighborsClassifier'),
(1, 'LogisticRegression'),
(2, 'LinearSVC'),
(3, 'GaussianNB'),
(4, 'DecisionTreeClassifier'),
(5, 'RandomForestClassifier'),
(6, 'GradientBoostingClassifier'),
(7, 'MLPClassifier'),
)
name = models.CharField(max_length=64, choices=ALGORITHM_NAME)
parameters = JSONField()
View
class CalcUpdateView(UpdateAPIView):
queryset = Calc.objects.all()
serializer_class = CalcSerializer
def perform_update(self, serializer):
instance = serializer.save()
algorithm = Algorithm.objects.get(pk=self.request.data['algorithm'])
print(algorithm.get_name_display())
Thanks in advance for help!