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 youRegards,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--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 YouRegards,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.
No comments:
Post a Comment