#26641: Unable to concatenate 2 fields when filtering
-------------------------------------+-------------------------------------
Reporter: FoxPotato | Owner: nobody
Type: Uncategorized | Status: closed
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution: invalid
Keywords: QuerySet.extra | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):
* status: new => closed
* needs_better_patch: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_docs: => 0
Comment:
You should be able to use the
[https://docs.djangoproject.com/en/1.9/ref/models/database-
functions/#concat Concat] functions for this purpose:
{{{
from django.db.models import Value
from django.db.models.functions import Concat
User.objects.annotate(
name=Concat('first_name', Value(' '), 'last_name'),
).filter(name__icontains=value)
}}}
Or simply using `Q` objects:
{{{#!python
from django.db.models import Q
User.objects.annotate.filter(
Q(first_name__icontains=value) | Q(last_name__icontains=value),
)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26641#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.205771f882a31525b739b78beffe0369%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.