Skip to content

Commit

Permalink
Contact: Add method for snippet chooser search
Browse files Browse the repository at this point in the history
Add method chooser_search to the model which can be used by the
snippet chooser. This method does a case blind "contains"-search
agains "first_name last_name".
  • Loading branch information
donald committed Aug 14, 2020
1 parent 7ba4ec7 commit f6753e4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mpicms/personal/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from django.core.validators import MaxValueValidator
from django.db.models import CharField, Value as V
from django.db.models.functions import Concat

from wagtail.core.models import Orderable
from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel, InlinePanel
Expand Down Expand Up @@ -146,6 +148,8 @@ def __str__(self):
else:
return self.email

def chooser_search(query):
return Contact.objects.annotate(display_name=Concat("first_name", V(" "), "last_name")).filter(display_name__icontains=query)

class Meta: # noqa
verbose_name = 'Contact'
Expand Down

0 comments on commit f6753e4

Please sign in to comment.