Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only allow unique emails for user accounts #212

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/users/migrations/0002_alter_customuser_email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2.15 on 2022-11-08 11:19

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [("users", "0001_initial")]

operations = [
migrations.AlterField(
model_name="customuser",
name="email",
field=models.EmailField(
error_messages={"unique": "A user with that email already exists."},
max_length=254,
unique=True,
verbose_name="email address",
),
)
]
10 changes: 9 additions & 1 deletion app/users/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
from django.contrib.auth.models import AbstractUser
from django.utils.translation import gettext_lazy as _
from django.db.models import EmailField


class CustomUser(AbstractUser):
pass
email = EmailField(
_("email address"),
blank=False,
error_messages={"unique": _("A user with that email already exists.")},
null=False,
unique=True,
)