Hi Shai, I was thinking about something very similar for the GIS backends, where this question is even more accurate, as lookup implementations are often very backend-specific.
I was experimenting with dynamic mixin registration, but that felt very hackish [1]. Anyway, a solution to this use case would be really welcome. Claude [1] https://gist.github.com/claudep/c234e546eab00ff9fdbf On Saturday, November 15, 2014 8:03:18 PM UTC+1, Shai Berger wrote: > > Hi, > > I'v been working on an old Oracle bug[1], and realized that a nice way to > solve it would be by overriding some builtin lookups with custom lookups > for > Oracle. However, I had some doubts about where to place the code: > > On the one hand, I could just add an "as_oracle()" to the builtin lookup > classes. But I felt that would be cheating -- Oracle is in core, but what > would 3rd-party backends do? > > So I thought I would implement a custom lookup in the backend, which adds > an > "as_oracle", and register that when the backend is loaded. Loic commented > that > this is still problematic -- For example, I want to override "contains" on > TextField's, so I would naturally inherit the built-in Contains lookup; > but if > a user has two backends which want to override "contains", they will be in > conflict -- only one of them will get to install its handler. > > The solution I found was to use dynamic inheritance -- the backend > inherits > not the builtin Contains, but the registered lookup for "contains" on > TextField. This way, another backend can also add its own as_vendor() > method, > without any of us stepping on each other's feet. > > I've posted the initial example of this as a PR[2] for comments. > > This is related to some of the discussions about transforms (SQL > Functions) > that happened on the mailing list a couple of months ago[3], but the topic > of > backend-specific functions was not really the topic there, so I preferred > to > open a new discussion. > > Have fun, > Shai. > > > [1] https://code.djangoproject.com/ticket/11580 > [2] https://github.com/django/django/pull/3544 > [3] > https://groups.google.com/d/msg/django-developers/HggiPzwkono/dsnx3BuXpnkJ > -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" 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]. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/276fb0e8-0ae5-41c5-bae7-8f482af20598%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
