From 7e675053b6d290f22884455050ac2ae5f2dcefc2 Mon Sep 17 00:00:00 2001 From: Tudor Amariei Date: Mon, 5 Feb 2024 11:25:58 +0200 Subject: [PATCH] Update username ID to a UUID --- backend/users/admin.py | 2 +- .../users/migrations/0002_alter_user_id.py | 19 +++++++++++++++++++ backend/users/models.py | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 backend/users/migrations/0002_alter_user_id.py diff --git a/backend/users/admin.py b/backend/users/admin.py index 30933e8a..930c0067 100644 --- a/backend/users/admin.py +++ b/backend/users/admin.py @@ -6,7 +6,7 @@ @admin.register(User) class UserAdmin(admin.ModelAdmin): list_display = ( - "id", + "pk", "email", ) list_display_links = ("email",) diff --git a/backend/users/migrations/0002_alter_user_id.py b/backend/users/migrations/0002_alter_user_id.py new file mode 100644 index 00000000..0a54096b --- /dev/null +++ b/backend/users/migrations/0002_alter_user_id.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.9 on 2024-02-05 09:24 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ("users", "0001_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="user", + name="id", + field=models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True), + ), + ] diff --git a/backend/users/models.py b/backend/users/models.py index 7b214b0e..4c03547f 100644 --- a/backend/users/models.py +++ b/backend/users/models.py @@ -45,6 +45,8 @@ class User(AbstractUser): instead of the username """ + id = models.UUIDField(primary_key=True, unique=True, default=uuid.uuid4, editable=False) + # We ignore the "username" field because the authentication # will be done by email + password username = models.CharField(