Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

94
Vistas
django 1.8 - QuerySet generated include columns not in values

I am trying to get a queryset displaying the average rate of comments. The query looks pretty simple - although Django seems to add automatically an extra field created_at in the generated group by statement. Is there any way to remove it from the group by clause ? Is it there because of the default order by defined in the META class of the models ?

GROUP BY "authentification_antenne"."name", "review"."created_at" instead of just GROUP BY "authentification_antenne"."name"

Review.objects.select_related(
'appartement__antenne').values('appartement__antenne__name').annotate(average_rating=Avg('rating')).query

SELECT 
"authentification_antenne"."name", AVG("review"."rating") AS "average_rating" FROM "review" 
LEFT OUTER JOIN "staffing_appartement" ON ( "review"."appartement_id" = "staffing_appartement"."numero_contrat" ) 
LEFT OUTER JOIN "authentification_antenne" ON ( "staffing_appartement"."antenne_id" = "authentification_antenne"."id" ) 
GROUP BY "authentification_antenne"."name", "review"."created_at" 
ORDER BY "review"."created_at" DESC

And the models.py

 class Review(models.Model):
     guest = models.ForeignKey(Guest)
     comment = models.TextField()
     rating = models.IntegerField(null=True)
     created_at = models.DateTimeField()
     imported_at = models.DateTimeField(auto_now=True)
     appartement = models.ForeignKey('staffing.appartement', null=True)

     class Meta:
         ordering = ['-created_at']

Edit - I confirm the statement generated is correct when the created_at ordering is removed from the models.

Edit 2 - I resolved this by adding my values in an order_by clause to remove the default filtering

AirbnbReview.objects.select_related('appartement__antenne').values('appartement__antenne__name').order_by('appartement__antenne__name').annotate(average_rating=Avg('rating'))

Thank you

about 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda