#9596: Comparing a DateTimeField to a date is too hard
-------------------------------------+-------------------------------------
     Reporter:  django@…             |                    Owner:  aaugustin
         Type:  New feature          |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  lookup_type date     |             Triage Stage:  Accepted
  datetimefield compare comparison   |
  query_term field lookup            |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by jdufresne):

 * cc: jon.dufresne@… (added)


Comment:

 > Now that #16187 is fixed this should be relatively easy to implement:
 > ...
 > DateTimeField.register_lookup(DateTransform)

 I've started down the path suggested above with commit:
 
https://github.com/jdufresne/django/commit/5bb3f1881982bc1248d5891a887725eeff7841bd

 However, I'm not sure where this code should live if added to Django
 generally. What is the correct area of the code to call
 `register_lookup()`?

 From the [https://docs.djangoproject.com/en/dev/howto/custom-lookups/
 docs]:

 > We can now use `foo__ne` for any field foo. You will need to ensure that
 this registration happens before you try to create any querysets using it.
 You could place the implementation in a `models.py` file, or register the
 lookup in the `ready()` method of an `AppConfig`.

 As far as I can tell, these options don't really apply to *built-in*
 transforms.

 I notice there is a `default_lookups` in `django/db/models/lookups.py`,
 but I'm not sure how to make this work for field specific transforms,
 instead of baisc lookups.

 I tried putting `register_lookup()` inside `django/db/fields/__init__.py`,
 however this lead to issues with settings.

 ```
 django.core.exceptions.ImproperlyConfigured: Requested setting
 DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either
 define the environment variable DJANGO_SETTINGS_MODULE or call
 settings.configure() before accessing settings.
 ```

 Any thoughts?

--
Ticket URL: <https://code.djangoproject.com/ticket/9596#comment:27>
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/074.a405b0b995bfd5f8dfac65b07a899609%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to