#24420: Can't order_by annotated field if annotated field uses conditional
expression
-------------------------+-------------------------------------------------
     Reporter:           |      Owner:  nobody
  krisfields             |
         Type:  Bug      |     Status:  new
    Component:           |    Version:  1.8beta1
  Uncategorized          |   Keywords:  order_by, annotation, conditional
     Severity:  Normal   |  expression
 Triage Stage:           |  Has patch:  0
  Unreviewed             |
Easy pickings:  0        |      UI/UX:  0
-------------------------+-------------------------------------------------
 Continuing with the Client example on
 https://docs.djangoproject.com/en/dev/ref/models/conditional-expressions/


 {{{
 from django.db import models

 class Client(models.Model):
     REGULAR = 'R'
     GOLD = 'G'
     PLATINUM = 'P'
     ACCOUNT_TYPE_CHOICES = (
         (REGULAR, 'Regular'),
         (GOLD, 'Gold'),
         (PLATINUM, 'Platinum'),
     )
     name = models.CharField(max_length=50)
     registered_on = models.DateField()
     account_type = models.CharField(
         max_length=1,
         choices=ACCOUNT_TYPE_CHOICES,
         default=REGULAR,
     )

 Client.objects.annotate(
     discount=Case(
         When(account_type=Client.GOLD, then=Value('5%')),
         When(account_type=Client.PLATINUM, then=Value('10%')),
         default=Value('0%'),
         output_field=CharField(),
         ),
     ).order_by('discount')
 }}}

 Error is:

 {{{
 <repr(<django.db.models.query.QuerySet at 0x10afaef10>) failed:
 AttributeError: 'WhereNode' object has no attribute 'resolve_expression'>
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24420>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/053.a8f77eeeac54e7ff6a7e412c767c4056%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to