﻿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
22766	Model derivated fields	luismasuelli@…	nobody	"It could be useful to allow a query to fetch additional fields for a bulk of objects.

Assume I have class Person as follows:

class Person(Model):

    first_name = CharField(max_length=30)
    last_name = CharField(max_length=30)

    @property
    def full_name(self):
        return self.first_name + ' ' + self.last_name

It's useful to have this propert but: what about serializing a large bulk of objects? E.g. generating:

[""John Lennon"", ""George Harrison"", ""Paul McCartney"", ""Ringo Starr""]

Assuming I have a bigger list (1000+ entries for some reason), this would require iterating over the whole list:

    return JSONResponse([person.full_name for person in Person.objects.all()]) #assume I have such object

My proposed solution is to have another queryset method like the ""annotate()"" but instead of fetching a statictical value from related objects, get a derivated value from the same object. It could be:

    Person.objects.all().derivated(full_name=F('first_name')+' '+F('last_name'))

and even in values() or values_list()

    Person.objects.all().values('first_name', 'last_name', full_name=F('first_name')+' '+F('last_name'))

Where the derivated fields come as kwargs."	New feature	closed	Database layer (models, ORM)	dev	Normal	duplicate			Unreviewed	0	0	0	0	0	0
