W
W
wawa2018-06-22 12:47:58
Django
wawa, 2018-06-22 12:47:58

How to refine an annotation in order_by if it conflicts with a field of the merged model?

Request:

Post.objects.select_related(
    'blog'
).annotate(
    v=42
).order_by(
    'v'
)

The problem is that Blog has a field named 'v' which ends up ambiguous 'ORDER BY v'. Postgres doesn't understand v is a blog field or annotation.
In jung, you can specify the model in order_by(): 'post__v', 'blog__v'. But I have an annotation and how to refine it - I do not understand. Maybe there is a solution?
Yes, you can change the name of the annotation, but for me it's inconvenient. I want to then refer to the annotation as post.v, and if the 'v' of the blog is needed, then post.blog.v.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question