I would to get your help on the following : I have two models Parent model and a Child Model:
class Rate(models.Model):
RATE_VOLTAGE_CHOICES = (
(BAJA_TENSION, "Low tension"),
(MEDIA_TENSION, "Mid tension"),
(ALTA_TENSION, "High tension")
)
rate_type = models.CharField(max_length=1, choices=RATE_TYPE_CHOICES, default="0")
class ParentRate(models.Model):
rate = models.ForeignKey(Rate, on_delete=models.SET_NULL, blank=True, null=True
)
so front-end wants to "filter" rate_type choice by Low tension, Mid Tension, and High tension as strings, they send strings so I am trying to use When Case object so I can filter then:
rates = ParentRate.objects.annotate(rate_voltage=Case(
When(rate__rate_type=Rate.BAJA_TENSION, then=Value('Low tension')),
When(rate__rate_type=Rate.MEDIA_TENSION, then=Value('Mid tension')),
When(rate__rate_type=Rate.ALTA_TENSION, then=Value('High tension')),
default=Value('Low tension'),
)
)
but I am getting the following error:
django.core.exceptions.FieldError: Cannot resolve expression type, unknown output_field