[python-uk] Tumbleweed badge

Kuba kuba.janoszek at gmail.com
Thu Oct 26 19:03:06 EDT 2017


Hi Hansel,


On 26 October 2017 at 18:52, Hansel Dunlop <hansel at interpretthis.org> wrote:

> Hi all,
>
> So I just got a notification from Stackoverflow that this question -
> https://stackoverflow.com/questions/46804936/custom-
> django-field-type-with-modified-column-look-up-in-select-part - was just
> awarded the tumbleweed badge (no, votes, no answers, and no views)...
>

> So throwing this open to the wider community here. I do suspect there is
> no way of doing this in Django. But I wish there was. Because I'm trying to
> create a custom translation infrastructure and it would help if I could
> just return the actual text in the query rather than the whole blob of json.
>


so just regarding this part: *Does Django have any hooks that let me
dynamically change the 'SELECT' part of the query?*

Writing custom SQL backend (with only one custom part - the compiler) would
be one relatively "easy" way to do that. As weird as it sounds it would
take one method to override and mess up with.
django.db.models.sql.compiler.SQLCompiler.as_sql is your friend. You'd need
to find a clever way to figure out if given compiled sql query is the one
you're interested in and only then alter it, to avoid performance
penalties. I'm not sure it's a good idea, but it is possible. Of course
it's quite deep in internals so passing any custom stuff there would be
anyway kinda "threadlocal-magical".

Regarding translations, just curious: have you considered django-hvad /
django-parler?

Cheers,
Jakub



>
> I mean maybe I could on the fly modify the db_column value. But would that
> be thread safe? Doubt it.
>
> --
>
>                                 Hansel
>
> _______________________________________________
> python-uk mailing list
> python-uk at python.org
> https://mail.python.org/mailman/listinfo/python-uk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-uk/attachments/20171027/a0d43bc6/attachment.html>


More information about the python-uk mailing list