Skip to content

list by related_name is empty #218

Answered by collerek
NikitaAleshnikov asked this question in Q&A
Discussion options

You must be logged in to vote

It's hard to tell without the actual code you use but i would guess you do not provide select_related or prefetch_related. If you query from chat the related models are not loaded by default. If you query from contest the models are not loaded by default too but you get a primary key only model (special model with only on populated that you can load in separate call)

So you need to run

chat = await Chat.objects.select_related("contests").get(id=xxx)
assert len(chat.contests)>0

#or you can use separate query if you already have chat
await chat.contests.all()

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@NikitaAleshnikov
Comment options

Answer selected by NikitaAleshnikov
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