I have a table that stores current values used to provide the data to render some charts.
One field in the model is a decimal, and when I get the values the list returned is of the format [Decimal:(x.x)…].
I’m guessing this is a python issue and not django; although I guess I could save the values in a CharField and convert to numerals…
I am trying to figure out what I am doing wrong, as all I want is the numerical values in the chart.
models.py:
class Final_Result(models.Model):
user_id = models.IntegerField(null = True, blank=False)
area = models.CharField(max_length=300)
scores = models.DecimalField(max_digits=2, decimal_places=1)
max_scores=models.IntegerField(blank = True)
survey = models.IntegerField(blank = True)
company = models.CharField(max_length=250, null = True)
area_id = models.IntegerField(null = True, blank=False)
overall_color = models.CharField(max_length=20, null = True)
survey_name = models.CharField(max_length=40, null = True)
length = models.IntegerField(blank = True)
def __str__(self):
return f"{self.user_id} company {self.company} survey {self.survey} area {self.area} score {self.scores} max {self.max_scores} "
Views.py that get the data:
def results_overall(request):
#user_id=request.user.id
user_id=1
area_name = list(Final_Result.objects.filter(user_id = user_id).values_list("area", flat=True))
area_scores = list(Final_Result.objects.filter(user_id = user_id).values_list("scores", flat=True))
print('area: ', area_name)
print('area score: ', area_scores)
return render(request,'ISO22301/results_overall.html')
Print output:
area: ['Risk Management Framework and Leadership', 'Organizational Context', 'Monitoring and Review', 'Communication and Consultation', 'Risk Response', 'Risk Assessment Process', 'Context of the Organization', 'Improvement', 'Mangement Review', 'Operations', 'Support', 'Policy and Planning', 'Leadership', 'Leadership and Governance', 'Long-Term Resilience Strategy', 'Supply Chain Resilience', 'Adaptation and Learning', 'Collaboration and Communication', 'Performance Monitoring and Improvement', 'Resource Management and Adaptability', 'Business Continuity and Crisis Management', 'Risk Management', 'Organizational Culture and Awareness']
area score: [Decimal('0.0'), Decimal('0.0'), Decimal('0.0'), Decimal('0.0'), Decimal('0.0'), Decimal('0.0'), Decimal('1.0'), Decimal('1.0'), Decimal('1.0'), Decimal('1.0'), Decimal('2.0'), Decimal('2.0'), Decimal('2.0'), Decimal('1.0'), Decimal('3.0'), Decimal('3.0'), Decimal('2.0'), Decimal('3.0'), Decimal('4.0'), Decimal('5.0'), Decimal('4.0'), Decimal('3.0'), Decimal('2.0')]
If I get Max_scores it is formatted as expected:
MAx score: [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]