When i try to follow the relationship with 'filter', the lookup is ignored:

Evaluacion.objects.values('id', 'periodo__indicador').filter(
periodo__indicador=1)

<QuerySet [{'id': 1, 'periodo__indicador': 1}, {'id': 1, 
'periodo__indicador': 2}, {'id': 1, 'periodo__indicador': 3}, {'id': 1, 
'periodo__indicador': 4}, {'id': 1, 'periodo__indicador': 5}, {'id': 1, 
'periodo__indicador': 6}, {'id': 1, 'periodo__indicador': 7}, {'id': 1, 
'periodo__indicador': 8}, {'id': 3, 'periodo__indicador': 1}, {'id': 3, 
'periodo__indicador': 2}, {'id': 3, 'periodo__indicador': 3}, {'id': 3, 
'periodo__indicador': 4}, {'id': 3, 'periodo__indicador': 5}, {'id': 3, 
'periodo__indicador': 6}, {'id': 3, 'periodo__indicador': 7}, {'id': 3, 
'periodo__indicador': 8}]>

My Django version is 2.1.7 and Python 3.7.2
My model is:

Class Periodo(models.Model):
    pass

Class Indicador(models.Model):
    periodo = models.ForeignKey(Periodo, on_delete=models.CASCADE)

class Evaluacion(models.Model):
    periodo = models.ForeignKey(Periodo, on_delete=models.CASCADE)



I think this is a bug, because documentation says:

Finally, note that you can call filter(), order_by(), etc. after the values
() call, that means that these two calls are identical:

Blog.objects.values().order_by('id')
Blog.objects.order_by('id').values()


I tried to change the order between 'values' and 'filter', and it worked:


Evaluacion.objects.filter(periodo__indicador=1).values('id', 
'periodo__indicador')
 <QuerySet [{'id': 1, 'periodo__indicador': 1}, {'id': 3, 'periodo__indicador': 
1}]>





-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7a05d3e6-addb-4dde-ae1e-36968aa822f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to