display name uniqueness

This commit is contained in:
Matteo Rosati
2026-02-11 12:26:54 +01:00
parent 6cbaf5f6ee
commit 01fd047568
4 changed files with 24 additions and 1 deletions

Binary file not shown.

View File

@@ -0,0 +1,15 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("frontend", "0001_userprofile"),
]
operations = [
migrations.AlterField(
model_name="userprofile",
name="display_name",
field=models.CharField(max_length=150, unique=True),
),
]

View File

@@ -10,7 +10,7 @@ class UserProfile(models.Model):
on_delete=models.CASCADE,
related_name="profile",
)
display_name = models.CharField(max_length=150)
display_name = models.CharField(max_length=150, unique=True)
def __str__(self):
return f"{self.display_name} ({self.user.username})" # type: ignore[attr-defined]

View File

@@ -53,6 +53,14 @@ def register(request: HttpRequest) -> HttpResponse:
if email and User.objects.filter(username=email).exists():
errors.append("An account with that email already exists.")
if (
display_name
and UserProfile.objects.filter( # type: ignore[attr-defined]
display_name=display_name
).exists()
):
errors.append("That display name is already taken.")
if errors:
for error in errors:
messages.error(request, error)