#25240: Add "week" lookup to DateField/DateTimeField
-------------------------------------+-------------------------------------
Reporter: foresmac | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: QuerySet.extra | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by jarshwah):
I'm fairly sure that this can be implemented in 1.9 with bilateral
transformations. 1.9 is only required because that is when `Now()` was
added. If you'd like to copy the implementation of `Now()` into your
current codebase, then you could get it to work in 1.8.
{{{
from django.db.models.fields import DateTransform
from django.db.models.functions import Now
class WeekTransform(DateTransform):
lookup_name = 'week'
bilateral = True
Model.objects.filter(timestamp__week__exact=Now())
}}}
So there's an argument to be made that `WeekTransform` could be added to
core, but without the `bilateral` argument in order to remain consistent
with the rest of the Date based transforms. I'm currently working on a
patch (#24629) that would allow the transform to be used explicitly on the
right hand side:
{{{
class WeekTransform(DateTransform):
lookup_name = 'week'
Model.objects.filter(timestamp__week__exact=WeekTransform(Now()))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25240#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.c33eb61181bf3641e6f97e9fd477700e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.