-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,32 @@ | ||
from django.contrib import admin # noqa | ||
""" | ||
Django admin customization | ||
""" | ||
from django.contrib import admin | ||
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
# Register your models here. | ||
from core import models | ||
|
||
|
||
class UserAdmin(BaseUserAdmin): | ||
"""Define the admin pages for users.""" | ||
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'] | ||
|
||
|
||
admin.site.register(models.User, UserAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
""" | ||
Tests for the Django admin modifications. | ||
""" | ||
from django.test import TestCase | ||
from django.contrib.auth import get_user_model | ||
from django.urls import reverse | ||
from django.test import Client | ||
|
||
|
||
class AdminSiteTests(TestCase): | ||
|
||
def setUp(self): | ||
self.client = Client() | ||
self.admin_user = get_user_model().objects.create_superuser( | ||
'[email protected]', | ||
'test123' | ||
) | ||
self.client.force_login(self.admin_user) | ||
self.user = get_user_model().objects.create_user( | ||
'[email protected]', | ||
'test123', | ||
name='Test User' | ||
) | ||
|
||
def test_users_list(self): | ||
url = reverse('admin:core_user_changelist') | ||
res = self.client.get(url) | ||
|
||
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) | ||
|