from django.db.models.functions import Concat from myapp.models import Person person = Person.objects.annotate(full_name=Concat('first_name', 'last_name')) print(person.full_name) # This will return the combination of first_name and last_name fields.
from django.db.models import Value from django.db.models.functions import Concat queryset = Person.objects.annotate( full_name=Concat('first_name', Value(' '), 'last_name') ) print(queryset[0].full_name) # This will return the full name with a space separator between first_name and last_name.
from django.db.models import F, Value from django.db.models.functions import Concat queryset = Person.objects.annotate( full_name=Concat(F('first_name'), Value(' '), F('last_name')) ) print(queryset[0].full_name) # This will return the full name with a space separator between first_name and last_name.The django.db.models.functions.Concat function is part of the Django framework and can be found in the django.db.models.functions package library.