diff --git a/db.sqlite3 b/db.sqlite3 index 0b687b4..69d08b4 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/frontend/migrations/0002_userprofile_display_name_unique.py b/frontend/migrations/0002_userprofile_display_name_unique.py new file mode 100644 index 0000000..231d0f1 --- /dev/null +++ b/frontend/migrations/0002_userprofile_display_name_unique.py @@ -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), + ), + ] diff --git a/frontend/models.py b/frontend/models.py index 8ab97e7..3e559e1 100644 --- a/frontend/models.py +++ b/frontend/models.py @@ -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] diff --git a/frontend/views.py b/frontend/views.py index 1977db0..37d9f89 100644 --- a/frontend/views.py +++ b/frontend/views.py @@ -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)