display name uniqueness
This commit is contained in:
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
15
frontend/migrations/0002_userprofile_display_name_unique.py
Normal file
15
frontend/migrations/0002_userprofile_display_name_unique.py
Normal 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),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -10,7 +10,7 @@ class UserProfile(models.Model):
|
|||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name="profile",
|
related_name="profile",
|
||||||
)
|
)
|
||||||
display_name = models.CharField(max_length=150)
|
display_name = models.CharField(max_length=150, unique=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.display_name} ({self.user.username})" # type: ignore[attr-defined]
|
return f"{self.display_name} ({self.user.username})" # type: ignore[attr-defined]
|
||||||
|
|||||||
@@ -53,6 +53,14 @@ def register(request: HttpRequest) -> HttpResponse:
|
|||||||
if email and User.objects.filter(username=email).exists():
|
if email and User.objects.filter(username=email).exists():
|
||||||
errors.append("An account with that email already 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:
|
if errors:
|
||||||
for error in errors:
|
for error in errors:
|
||||||
messages.error(request, error)
|
messages.error(request, error)
|
||||||
|
|||||||
Reference in New Issue
Block a user