You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class AdvanceBill(models.Model):
date = models.DateField()
total = models.DecimalField(max_digits=12, decimal_places=2)
number = models.CharField(max_length=10)
# other fields
class Meta:
ordering = ("-date", "-number")
the result is not grouped by values (the same dates have multiple occurences in the result) as the query looks like this (note that values only accept "date" and we have date and number in GROUP BY clause and ORDER BY is applied anyway):
SELECT `accounting_advancebill`.`date`, SUM(`accounting_advancebill`.`total`) AS `x_total_sum` FROM `accounting_advancebill` GROUP BY `accounting_advancebill`.`date`, `accounting_advancebill`.`number` ORDER BY `accounting_advancebill`.`date` DESC, `accounting_advancebill`.`number` DESC LIMIT 10
This happens when the model uses MultilingualQuerySet, (MultilingualManager) if standard QuerySet is used, order_by() removes ordering as expected:
SELECT `accounting_advancebill`.`date`, SUM(`accounting_advancebill`.`total`) AS `x_total_sum` FROM `accounting_advancebill` GROUP BY `accounting_advancebill`.`date` ORDER BY NULL LIMIT 10
The text was updated successfully, but these errors were encountered:
Consider the following model:
If I try running the following statement:
AdvanceBill.objects.all().values("date").annotate(x_total_sum=Sum(F("total"))).order_by()[:10]
the result is not grouped by values (the same dates have multiple occurences in the result) as the query looks like this (note that
values
only accept"date"
and we havedate
andnumber
inGROUP BY
clause andORDER BY
is applied anyway):SELECT `accounting_advancebill`.`date`, SUM(`accounting_advancebill`.`total`) AS `x_total_sum` FROM `accounting_advancebill` GROUP BY `accounting_advancebill`.`date`, `accounting_advancebill`.`number` ORDER BY `accounting_advancebill`.`date` DESC, `accounting_advancebill`.`number` DESC LIMIT 10
This happens when the model uses
MultilingualQuerySet
, (MultilingualManager
) if standardQuerySet
is used,order_by()
removes ordering as expected:SELECT `accounting_advancebill`.`date`, SUM(`accounting_advancebill`.`total`) AS `x_total_sum` FROM `accounting_advancebill` GROUP BY `accounting_advancebill`.`date` ORDER BY NULL LIMIT 10
The text was updated successfully, but these errors were encountered: