Opened 14 years ago
Closed 10 years ago
#16092 closed Bug (wontfix)
QuerySet F() fields should be able to reference .extra() select keys
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.3 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
from django.db import models from datetime import datetime class TestModel(models.Model): word = models.CharField(max_length=50) timezone_name = models.CharField(max_length=200) cutoff = models.DateTimeField() class Meta: db_table = 'test_model' obj1 = TestModel.objects.create(word='Foo', timezone_name='America/New_York', cutoff=datetime(2012,1,1,0,0,0)) obj2 = TestModel.objects.create(word='Bar', timezone_name='America/Los_Angeles', cutoff=datetime(2000,1,1,0,0,0)) qs = TestModel.objects.extra(select={'now_in_local_tz': "convert_tz(now(), 'GMT', test_model.timezone_name)"}) qs = qs.filter(cutoff__lte=models.F('now_in_local_tz')) # FieldError: Cannot resolve keyword 'now_in_local_tz' into field. Choices are: cutoff, id, timezone_name, word
Disclaimer: I wrote the above code without testing it based on a far more complex real-world example - any typos ought not invalidate the bug.
Attachments (1)
Change History (4)
by , 14 years ago
Attachment: | 16092-testcase.patch added |
---|
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 10 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I think the new expressions API in Django 1.8 mostly obsoletes this. The plan is to deprecate .extra()
when all of its functionality can be achieved in other ways.
Note:
See TracTickets
for help on using tickets.
Here is a formal test case based on the example in the original report.