Friday, May 29, 2020

Re: Optimized Query

They both work for both.


On Fri, May 29, 2020 at 12:47 PM Sencer Hamarat <sencerhamarat@gmail.com> wrote:
I thought select_related works for only FK/M2M and prefetch_related works for only reverse relations, doesn't it?

Saygılarımla,
Sencer HAMARAT



‪On Fri, May 29, 2020 at 7:32 AM ‫אורי‬‎ <uri@speedy.net> wrote:‬
Hi Soumen,

Sometimes prefetch_related is much faster and more efficient than select_related. I usually prefer to use prefetch_related.

Uri.


On Thu, May 28, 2020 at 12:42 AM Soumen Khatua <soumenkhatua258@gmail.com> wrote:
Actually I want to fetch all users from User table and users location from Location table which is many to many relation from same Profile table. Is it possible??? 

On Thu 28 May, 2020, 2:54 AM Soumen Khatua, <soumenkhatua258@gmail.com> wrote:
Now I'm facing one problem whenever I'm trying to iterate a loop I'm getting too many SQL variables. Actually after iterating the loop I want to render all the value in the template.
if could you resolve this it would be very good for me.
Thank you for your time and response

Regards,
Soumen


On Thu, May 28, 2020 at 2:12 AM Chetan Ganji <ganji.chetan@gmail.com> wrote:
Profile.objects.filter().select_related("user").prefetch_related("location")

On Thu, May 28, 2020, 2:01 AM Soumen Khatua <soumenkhatua258@gmail.com> wrote:
I also know about this concept but I don't how I can achieve it, Could you give me an example?
Suppose I have:

class Profile(models.Model):
    user = models.OneToOneField(
        settings.AUTH_USER_MODEL,
        on_delete = models.CASCADE,
        related_name="profile"
    )
    location = models.ManyToManyField(Location)



Thank you

Regards,
Soumen

On Wed, May 27, 2020 at 7:20 PM Chetan Ganji <ganji.chetan@gmail.com> wrote:
select_related for fk and prefetch_related for m2m in django, you can chain them together 

Regards,
Chetan Ganji
+91-900-483-4183


On Wed, May 27, 2020 at 4:51 PM Soumen Khatua <soumenkhatua258@gmail.com> wrote:
Hi Folks,
I have many to many relationships and Foreign Key in the table, I'm using select_realted(foreign key filed name) to optimize the query but I want to fetch many to many and foreign key at the same time , How I can do this in very optimized way?

Thank You
Regards,
Soumen

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6Wb6f-BCwUZfvgzGtsrbV1seq1iGbXyuqoH%3DKxZrJ2EyLg%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMKMUju19j7apa1pXZQcZTY-6ThTJC%3DAL2eQhtO7DL2oTk6Oog%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6WZXtTJssu6SwO8_BiTDxDnzJtKYy9j1hQsMR74jKYC6aA%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMKMUjth%3DNm%2BUa74bz1PiRYFGhKU-PER9_Y_XQdHRQ23KMbp7Q%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6WY0T5U10NpzTXcsmdsvx641cdDiYJaU%2B3DEjzmb3iPDEA%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABD5YeHSOsjsFn1r8iG8fqPyqn1Q2j6O4-_9ozxtocofBgfBfA%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACp8TZghcG804q%2BBtx-z4mxNXZsh4f9iJpTDOvod%3DqphaCoyaQ%40mail.gmail.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABD5YeHc-HBhc%3DkawDTaZgiGK4GZsvsWRn5LayeyGxtpL4_75w%40mail.gmail.com.

No comments:

Post a Comment