#25676: Queryset.extra planned deprecation - Sorting a calculated field -------------------------------------+------------------------------------- Reporter: YunJD | Owner: nobody Type: Uncategorized | Status: new Component: Database layer | Version: 1.7 (models, ORM) | Severity: Normal | Resolution: Keywords: Queryset.extra | Triage Stage: | Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by sir-sigurd): Replying to [ticket:25676 YunJD]: {{{ In [12]: qs = Test.objects.annotate(calculated=F('a')/F('b')) In [13]: list(qs.order_by('calculated').values()) Out[13]: [{'a': 60.0, 'b': 128.0, 'calculated': 0.46875, u'id': 2}, {'a': 1.0, 'b': 2.0, 'calculated': 0.5, u'id': 1}] In [14]: list(qs.order_by('-calculated').values()) Out[14]: [{'a': 1.0, 'b': 2.0, 'calculated': 0.5, u'id': 1}, {'a': 60.0, 'b': 128.0, 'calculated': 0.46875, u'id': 2}] In [15]: list(qs.filter(calculated__lt=0.5).order_by('-calculated').values()) Out[15]: [{'a': 60.0, 'b': 128.0, 'calculated': 0.46875, u'id': 2}] }}} Does this answer to your question? -- Ticket URL: <https://code.djangoproject.com/ticket/25676#comment:3> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.25c4f02e965203b1834a5d5c062b2f1a%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.