diff --git a/backend/project/accounts/admin.py b/backend/project/accounts/admin.py index 6625799..98ccf7f 100644 --- a/backend/project/accounts/admin.py +++ b/backend/project/accounts/admin.py @@ -13,6 +13,7 @@ class UserAdmin(BaseUserAdmin): "email", "first_name", "last_name", + "uuid", "is_active", "is_superuser", "date_joined", @@ -22,7 +23,7 @@ class UserAdmin(BaseUserAdmin): "is_superuser", "is_active", ) - search_fields = ("email", "first_name", "last_name") + search_fields = ("email", "first_name", "last_name", "uuid") ordering = ("email",) fieldsets = ( (None, {"fields": ("email", "password")}), @@ -48,6 +49,7 @@ class UserAdmin(BaseUserAdmin): ), (_("Important dates"), {"fields": ("last_login", "date_joined")}), ) + readonly_fields = ("date_joined", "last_login", "uuid") admin.site.register(User, UserAdmin) diff --git a/backend/project/accounts/migrations/0002_user_uuid.py b/backend/project/accounts/migrations/0002_user_uuid.py new file mode 100644 index 0000000..4faa62a --- /dev/null +++ b/backend/project/accounts/migrations/0002_user_uuid.py @@ -0,0 +1,24 @@ +# Generated by Django 5.0.6 on 2024-07-02 13:58 + +import django.contrib.postgres.functions +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("accounts", "0001_initial"), + ] + + operations = [ + migrations.AddField( + model_name="user", + name="uuid", + field=models.UUIDField( + db_default=django.contrib.postgres.functions.RandomUUID(), + db_index=True, + editable=False, + unique=True, + ), + ), + ] diff --git a/backend/project/accounts/models.py b/backend/project/accounts/models.py index 7a1642f..b94ebb9 100644 --- a/backend/project/accounts/models.py +++ b/backend/project/accounts/models.py @@ -1,5 +1,6 @@ from django.contrib.auth.base_user import AbstractBaseUser from django.contrib.auth.models import PermissionsMixin +from django.contrib.postgres.functions import RandomUUID from django.db import models from django.db.models.functions import Now from django.utils import timezone @@ -9,6 +10,9 @@ class User(AbstractBaseUser, PermissionsMixin): + uuid = models.UUIDField( + editable=False, unique=True, db_index=True, db_default=RandomUUID() + ) email = models.EmailField( _("email address"), unique=True,