Skip to content

Commit

Permalink
add UUID field on user model
Browse files Browse the repository at this point in the history
  • Loading branch information
submarcos committed Jul 2, 2024
1 parent ddb9309 commit b83d1c5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion backend/project/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class UserAdmin(BaseUserAdmin):
"email",
"first_name",
"last_name",
"uuid",
"is_active",
"is_superuser",
"date_joined",
Expand All @@ -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")}),
Expand All @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions backend/project/accounts/migrations/0002_user_uuid.py
Original file line number Diff line number Diff line change
@@ -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,
),
),
]
4 changes: 4 additions & 0 deletions backend/project/accounts/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down

0 comments on commit b83d1c5

Please sign in to comment.