Skip to content

Commit

Permalink
modified user page for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
nishu-saini committed Nov 2, 2023
1 parent 6133ead commit 750d0d7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
41 changes: 41 additions & 0 deletions app/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
15 changes: 15 additions & 0 deletions app/core/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 750d0d7

Please sign in to comment.