Skip to content

use sql from queryset #32

Answered by jokiefer
jokiefer asked this question in Q&A
Nov 23, 2023 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

Finally i made it!

Django does not interpolate the parameters from the query. See hint from stackoverflow for description.

So the key was to trigger the execution of the query to get the correct evaluated sql statement from it. See django docs for more details.

My solution is the following:

    @classmethod
    def get_sql(cls):
        repr(MetadataRelation.objects.for_search()) # this will trigger the execition
        last_query = connection.queries[-1].get('sql') # get the last query; this should be the execution from the line below
        return pg.ViewSQL(last_query, None)

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@jokiefer
Comment options

@jokiefer
Comment options

@jokiefer
Comment options

Answer selected by jokiefer
@jokiefer
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants