#25403: A quite common use of .extra()
----------------------------------------------+----------------------------
     Reporter:  PaoloC68                      |      Owner:  nobody
         Type:  New feature                   |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.8
     Severity:  Normal                        |   Keywords:  QuerySet.extra
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+----------------------------
 As written in the documentation I submit a use case where the `.extra()`
 method seems the only way to do what I need. Given this model:
 {{{
         from django.db import models


         class Post(models.Model):
             text = models.CharField(max_length=255)


         class Comment(models.Model):
             text = models.CharField(max_length=255)
             needs_attention = models.BooleanField(default=False)
             created_at = models.DateTimeField(auto_now_add=True)
             post = models.ForeignKey(Post)

 }}}

 I can `annotate` the list of posts with:

 {{{
 Post.objects.annotate(last_comment_date=Max('comment__created_at'))
 }}}


 to know the `last_comment_date`, how to annotate to set a value for
 `last_comment_needs_attention`?

 I mean how can I obtain more informations from the comments while listing
 the `posts`?

 I see that this is a quite common request as a feature of the Django ORM,
 the most detailed description of this problem can be found in
 [http://blog.roseman.org.uk/2010/08/14/getting-related-item-aggregate/
 this nice blog post] .

 Is there any plan to allow such a way to annotate? Thx

--
Ticket URL: <https://code.djangoproject.com/ticket/25403>
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/051.8d09eabbf4ae8e2b29581fcb79a234a2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to