From 899017c01a7106167423ea1c0a0cf8cdbbd5ba9c Mon Sep 17 00:00:00 2001 From: Ethan Nguyen Date: Fri, 23 Apr 2021 20:00:19 -0400 Subject: [PATCH] feat(authentication): add last modified, redo admin interface --- tjdests/apps/authentication/admin.py | 34 +++++++++++++++++++ .../migrations/0009_user_last_modified.py | 18 ++++++++++ tjdests/apps/authentication/models.py | 2 ++ 3 files changed, 54 insertions(+) create mode 100644 tjdests/apps/authentication/migrations/0009_user_last_modified.py diff --git a/tjdests/apps/authentication/admin.py b/tjdests/apps/authentication/admin.py index 34642d0..56d7f46 100644 --- a/tjdests/apps/authentication/admin.py +++ b/tjdests/apps/authentication/admin.py @@ -5,6 +5,40 @@ from .models import User class UserAdmin(admin.ModelAdmin): search_fields = ["username", "first_name", "last_name"] + list_display = ["username", "last_name", "first_name", "last_modified"] + list_filter = ["is_senior", "accepted_terms", "is_student"] + + fieldsets = ( + ( + None, + { + "fields": ( + "username", + "first_name", + "last_name", + "email", + "password", + "accepted_terms", + "is_staff", + "is_superuser", + "is_senior", + "graduation_year", + "is_student", + "last_modified", + "last_login", + ) + }, + ), + ( + "Senior information", + {"fields": ("biography", "attending_decision", "publish_data")}, + ), + ) + + readonly_fields = ( + "last_modified", + "last_login", + ) admin.site.register(User, UserAdmin) diff --git a/tjdests/apps/authentication/migrations/0009_user_last_modified.py b/tjdests/apps/authentication/migrations/0009_user_last_modified.py new file mode 100644 index 0000000..ff554f8 --- /dev/null +++ b/tjdests/apps/authentication/migrations/0009_user_last_modified.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2 on 2021-04-23 17:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("authentication", "0008_alter_user_biography"), + ] + + operations = [ + migrations.AddField( + model_name="user", + name="last_modified", + field=models.DateTimeField(auto_now=True), + ), + ] diff --git a/tjdests/apps/authentication/models.py b/tjdests/apps/authentication/models.py index a40a3ad..60a6098 100644 --- a/tjdests/apps/authentication/models.py +++ b/tjdests/apps/authentication/models.py @@ -31,5 +31,7 @@ class User(AbstractUser): help_text="Can't see your college? Make sure you've added a decision with an admit status.", ) + last_modified = models.DateTimeField(auto_now=True) + def __str__(self): return f"{self.first_name} {self.last_name}"