From fbaf914c8be926c2449d4707c27a2b75e2340b76 Mon Sep 17 00:00:00 2001 From: David Bruno Vontor Date: Fri, 5 Jun 2026 16:48:53 +0200 Subject: [PATCH] Improve user search, DB nulls, and chat UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change username filter to use icontains for partial/case-insensitive matching. In CustomUser.save, introduce _NULLABLE_CHAR_FIELDS and convert empty string char fields to None to ensure nullable fields are stored consistently. Update CreateChatModal to always show a subtitle combining the user's full name and account creation date (joined with " · "), improving UI information. --- backend/account/filters.py | 2 +- backend/account/models.py | 6 ++++++ .../components/social/chat/CreateChatModal.tsx | 17 ++++++++++------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/backend/account/filters.py b/backend/account/filters.py index 53f316f..1d26d63 100644 --- a/backend/account/filters.py +++ b/backend/account/filters.py @@ -4,7 +4,7 @@ from django.contrib.auth import get_user_model User = get_user_model() class UserFilter(django_filters.FilterSet): - username = django_filters.CharFilter(field_name="username", lookup_expr="exact") + username = django_filters.CharFilter(field_name="username", lookup_expr="icontains") role = django_filters.CharFilter(field_name="role", lookup_expr="exact") email = django_filters.CharFilter(field_name="email", lookup_expr="icontains") phone_number = django_filters.CharFilter(field_name="phone_number", lookup_expr="icontains") diff --git a/backend/account/models.py b/backend/account/models.py index 716be9d..88de28f 100644 --- a/backend/account/models.py +++ b/backend/account/models.py @@ -116,7 +116,13 @@ class CustomUser(SoftDeleteModel, AbstractUser): return super().delete(*args, **kwargs) + _NULLABLE_CHAR_FIELDS = ('phone_number', 'city', 'street', 'country', 'postal_code', 'email_verification_token') + def save(self, *args, **kwargs): + for field in self._NULLABLE_CHAR_FIELDS: + if not getattr(self, field): + setattr(self, field, None) + is_new = self._state.adding # True if object hasn't been saved yet # Pre-save flags for new users diff --git a/frontend/src/components/social/chat/CreateChatModal.tsx b/frontend/src/components/social/chat/CreateChatModal.tsx index 8a2b5df..e62470e 100644 --- a/frontend/src/components/social/chat/CreateChatModal.tsx +++ b/frontend/src/components/social/chat/CreateChatModal.tsx @@ -292,13 +292,16 @@ export default function CreateChatModal({ open, onClose }: Props) {
{user.username}
- {(user.first_name || user.last_name) && ( -
- {[user.first_name, user.last_name] - .filter(Boolean) - .join(" ")} -
- )} +
+ {[ + [user.first_name, user.last_name].filter(Boolean).join(" "), + user.create_time + ? new Date(user.create_time).toLocaleDateString() + : null, + ] + .filter(Boolean) + .join(" · ")} +
{selectedUsers.some((s) => s.id === user.id) && (