Hello, Provided:
class M(models.Model): n = models.IntegerField() r = models.IntegerField() t = models.IntegerField() s = models.IntegerField() u = models.IntegerField() class F(models.Model): g = models.ForeignKey(M, on_delete=models.CASCADE) a = models.IntegerField() b = models.IntegerField() c = models.IntegerField() d = models.IntegerField() e = models.IntegerField() I want to obtain with a queryset all fields from F and M.n, but not the other fields of M like M.r, so that a single SELECT is generated, that doesn't pick unnecessary columns. F.objects.select_related('g').defer('g__r', 'g__t', 'g__s', 'g__u') does work, but I don't like it, as I want to say only M.n has to be obtained, and not the others. prefetch_related() is also suboptimal, as it creates two SQL queries instead of one. only() does not let me specify 'All fields of F'. So here neither only() nor defer() nor prefetch_related() are good. F.objects.select_related('g__n') would fit from logic, but does not work (django.core.exceptions.FieldError: Non-relational field given in select_related: 'n'. Choices are: (none)) I propose teaching select_related() to accept the above expression. Confer https://code.djangoproject.com/ticket/29072 . Regards Дилян -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To post to this group, send email to django-developers@googlegroups.com. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/d9a58b37-d084-2efe-33b0-4cd9b8289796%40aegee.org. For more options, visit https://groups.google.com/d/optout.