I have two models from different apps:
class Measure(models.Model):
date = models.DateTimeField(default="2018-01-23 15:55")
average = models.FloatField(default=0)
class Sensor(models.Model):
measure=models.ForeignKey(Measure, on_delete=models.CASCADE)
value= models.FloatField(default=0)
I'm calling all data coming from sensors as follow:
new_context = Sensor.objects.select_related('measure__date')
However, I receive this error:
django.core.exceptions.FieldError: Non-relational field given in select_related: 'date'. Choices are: (none)
from documentation, I should be using select_related instead of prefetch_related, and the call seems to be coherent.
Am I missing something?
Sensor.objects.select_related('measure')
. After that you may get the attributes from the queryset. – Seduction