All indexed fields are autocompleted

This commit is contained in:
Yohann D'ANELLO 2020-10-15 14:55:45 +02:00
parent 11ebc6848b
commit 980b2c9d8e
5 changed files with 13 additions and 11 deletions

View File

@ -1,12 +1,11 @@
import re
from django.urls import reverse_lazy
from corres2math.lists import get_sympa_client
from django.core.exceptions import ObjectDoesNotExist
from django.core.validators import RegexValidator
from django.db import models
from django.db.models import Index
from django.urls import reverse_lazy
from django.utils.crypto import get_random_string
from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy as _
@ -121,7 +120,7 @@ class Participation(models.Model):
)
def get_absolute_url(self):
return reverse_lazy("participation:team_detail", args=(self.pk,))
return reverse_lazy("participation:participation_detail", args=(self.pk,))
def __str__(self):
return _("Participation of the team {name} ({trigram})").format(name=self.team.name, trigram=self.team.trigram)

View File

@ -4,15 +4,15 @@ from .models import Participation, Team, Video
class TeamIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, model_attr="name")
trigram = indexes.CharField(model_attr="trigram")
text = indexes.EdgeNgramField(document=True, model_attr="name")
trigram = indexes.EdgeNgramField(model_attr="trigram")
def get_model(self):
return Team
class ParticipationIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, model_attr="team__trigram")
text = indexes.EdgeNgramField(document=True, model_attr="team__name")
def get_model(self):
return Participation

View File

@ -2,6 +2,7 @@ from corres2math.tokens import email_validation_token
from django.contrib.sites.models import Site
from django.db import models
from django.template import loader
from django.urls import reverse_lazy
from django.utils.crypto import get_random_string
from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
@ -63,6 +64,9 @@ class Registration(PolymorphicModel):
def is_admin(self):
return isinstance(self, AdminRegistration) or self.user.is_superuser
def get_absolute_url(self):
return reverse_lazy("registration:user_detail", args=(self.user_id,))
def __str__(self):
return f"{self.user.first_name} {self.user.last_name}"

View File

@ -4,10 +4,10 @@ from .models import Registration
class RegistrationIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, model_attr="user__username")
last_name = indexes.CharField(model_attr="user__last_name")
first_name = indexes.CharField(model_attr="user__first_name")
email = indexes.CharField(model_attr="user__email")
text = indexes.EdgeNgramField(document=True, model_attr="user__username")
last_name = indexes.EdgeNgramField(model_attr="user__last_name")
first_name = indexes.EdgeNgramField(model_attr="user__first_name")
email = indexes.EdgeNgramField(model_attr="user__email")
def get_model(self):
return Registration

View File

@ -13,7 +13,6 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
from django.views.defaults import bad_request, permission_denied, page_not_found, server_error