#25403: A quite common use of .extra()
-------------------------------------+-------------------------------------
Reporter: PaoloC68 | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(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
-------------------------------------+-------------------------------------
Changes (by charettes):
* version: 1.8 => master
Comment:
I'm not sure if there's already a ticket tracking this feature request but
Anssi would know.
I guess we could provide an API similar to the
`prefetch_related()`/`Prefetch()` one.
{{{#!python
from django.db import models
from django.utils import timezone
class Post(models.Model):
text = models.CharField(max_length=255)
class Comment(models.Model):
post = models.ForeignKey(Post, related_name='comments')
text = models.CharField(max_length=255)
created_at = models.DateTimeField(default=timezone.now)
Post.objects.select_related(
latest_comment=Related(
'comments', queryset=Comments.objects.order_by('-created_at')
)
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25403#comment:2>
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/066.1aa7f53a485d702687183e52558bf4f2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.