Can anyone help please?

Am 2018-10-11 um 16:58 schrieb Carsten Fuchs:
Dear Django group,

with Django 1.11.15, using the example models Blog and Entry at <https://docs.djangoproject.com/en/2.1/topics/db/queries/#related-objects> for reference, I have code like this:

     b = Blog.objects.get(name="...")
     for e in b.entry_set.all():
         print(e.blog)

Obviously, e.blog == b, but I found that for each e, the access to e.blog causes a subquery to fetch the blog object.

While I understand the concepts of select_related() and prefetch_related(), I was surprised that the e.blog attributes are not prepopulated with b. Why is that and what is the proper way to fix the problem?

Best regards,
Carsten


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/80c901cb-33c3-8ba8-a359-393cf00ca53d%40cafu.de.
For more options, visit https://groups.google.com/d/optout.

Reply via email to