我不知道如何有效地计算单个反馈中的“好”或“坏”(从所有字段中计算,平均计算此反馈有多少好)
Mymodels.py如下所示
class Feedback(models.Model):
...
class FeedbackOption(models.TextChoices):
BAD = "BAD", "Bad"
GOOD = "GOOD", "Good"
...
comment = models.TextField()
timestamp = models.DateTimeField(auto_now_add=True, blank=True, null=True)
overall_experience = models.CharField(max_length=32, choices=FeedbackOption.choices)
doctor_checkup = models.CharField(max_length=32, choices=FeedbackOption.choices)
staff_behavior = models.CharField(max_length=32, choices=FeedbackOption.choices)
clinic_environment = models.CharField(max_length=32, choices=FeedbackOption.choices)
我不认为有一个很好的方法来计算多个字段。如果要计算一个字段,则可以使用GROUP BY函数:
但是,这对于多个领域来说是行不通的。在这种情况下,您可以添加如下属性方法:
替代解决方案
现在,如果可能,可以重新设计模型,如:
然后,您可以简单地查询:
相关问题 更多 >
编程相关推荐