list by related_name is empty #218
Answered
by
collerek
NikitaAleshnikov
asked this question in
Q&A
-
Models: |
Beta Was this translation helpful? Give feedback.
Answered by
collerek
Jun 2, 2021
Replies: 1 comment 1 reply
-
It's hard to tell without the actual code you use but i would guess you do not provide 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() |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
NikitaAleshnikov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's hard to tell without the actual code you use but i would guess you do not provide
select_related
orprefetch_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