#32122: Querying GenericIPAddressField for inexact matches requires use of
QuerySet.extra
-------------------------------------+-------------------------------------
     Reporter:  Peter Law            |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  closed
    Component:  Database layer       |                  Version:  2.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  wontfix
     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 Simon Charette):

 * status:  new => closed
 * resolution:   => wontfix


Comment:

 I suggest you have a look at the
 [https://docs.djangoproject.com/en/3.1/howto/custom-lookups/#custom-
 lookups custom lookups] documentation.

 Something along these lines should work

 {{{#!python
 from django.db.models import Lookup

 class GenericIPAddressFieldContainedBy(Lookup):
     name = 'contained_by'

     def as_postgresql(self, compiler, connection):
         lhs, lhs_params = self.process_lhs(compiler, connection)
         rhs, rhs_params = self.process_rhs(compiler, connection)
         params = lhs_params + rhs_params
         return '%s << %s' % (lhs, rhs), params

 models.GenericIPAddressField.register_lookup(GenericIPAddressFieldContainedBy)
 }}}

 Please TicketClosingReasons/UseSupportChannels next time as this is likely
 something you could have received support for there.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32122#comment:1>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.fa97dedb9d3d1a6f1555f68f38233731%40djangoproject.com.

Reply via email to