From 750d0d7d0e8a4916b67c8f6f0244d0c5449427c9 Mon Sep 17 00:00:00 2001 From: quarnstric Date: Thu, 2 Nov 2023 22:13:15 +0530 Subject: [PATCH] modified user page for admin --- app/core/admin.py | 41 ++++++++++++++++++++++++++++++++++++ app/core/tests/test_admin.py | 15 +++++++++++++ 2 files changed, 56 insertions(+) diff --git a/app/core/admin.py b/app/core/admin.py index 63b3351..af35ac7 100644 --- a/app/core/admin.py +++ b/app/core/admin.py @@ -3,6 +3,7 @@ """ from django.contrib import admin from django.contrib.auth.admin import UserAdmin as BaseUserAdmin +from django.utils.translation import gettext_lazy as _ from core import models @@ -12,5 +13,45 @@ class UserAdmin(BaseUserAdmin): ordering = ['id'] list_display = ['email', 'name'] + fieldsets = ( + ( + None, + { + 'fields': ('email','password'), + } + ), + ( + _('Permissions'), + { + 'fields': ('is_active','is_staff', 'is_superuser'), + } + ), + ( + _('Important dates'), + { + 'fields': ('last_login',), + } + ), + ) + readonly_fields = ['last_login'] + + add_fieldsets = ( + ( + None, + { + 'classes': ('wide',), + 'fields': ( + 'email', + 'password1', + 'password2', + 'name', + 'is_active', + 'is_staff', + 'is_superuser', + ) + } + ), + ) + admin.site.register(models.User, UserAdmin) \ No newline at end of file diff --git a/app/core/tests/test_admin.py b/app/core/tests/test_admin.py index 5b62082..b137075 100644 --- a/app/core/tests/test_admin.py +++ b/app/core/tests/test_admin.py @@ -33,3 +33,18 @@ def test_users_list(self): self.assertContains(res, self.user.name) self.assertContains(res, self.user.email) + + def test_edit_user_page(self): + """Test the edit user page works""" + url = reverse('admin:core_user_change', args=[self.user.id]) + res = self.client.get(url) + + self.assertEqual(res.status_code, 200) + + + def test_create_user_page(self): + """Test the create user page works""" + url = reverse('admin:core_user_add') + res = self.client.get(url) + + self.assertEqual(res.status_code, 200) \ No newline at end of file