﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29072	Allow select_related() to fetch individual fields from a related model	Дилян Палаузов	nobody	"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.  This works {{{F.objects.select_related('g').defer('g__r', 'g__t', 'g__s', 'g__u')}}} 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'.

{{{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)}}})

Please make {{{select_related()}}} accept the above expression.

This applies to both master and 1.11."	New feature	closed	Database layer (models, ORM)	dev	Normal	wontfix			Unreviewed	0	0	0	0	0	0
