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 <[email protected]> wrote: > select_related for fk and prefetch_related for m2m in django, you can > chain them together > > Regards, > Chetan Ganji > +91-900-483-4183 > [email protected] > http://ryucoder.in > > > On Wed, May 27, 2020 at 4:51 PM Soumen Khatua <[email protected]> > 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 [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CAPUw6Wb6f-BCwUZfvgzGtsrbV1seq1iGbXyuqoH%3DKxZrJ2EyLg%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-users/CAPUw6Wb6f-BCwUZfvgzGtsrbV1seq1iGbXyuqoH%3DKxZrJ2EyLg%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAMKMUju19j7apa1pXZQcZTY-6ThTJC%3DAL2eQhtO7DL2oTk6Oog%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAMKMUju19j7apa1pXZQcZTY-6ThTJC%3DAL2eQhtO7DL2oTk6Oog%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6WZXtTJssu6SwO8_BiTDxDnzJtKYy9j1hQsMR74jKYC6aA%40mail.gmail.com.

