102 lines
2.4 KiB
Python
102 lines
2.4 KiB
Python
from django.contrib import admin
|
||
from django.contrib.auth.forms import ReadOnlyPasswordHashField
|
||
from django import forms
|
||
from django.contrib.auth.admin import UserAdmin
|
||
from foldbank.models import (
|
||
Account,
|
||
Bank,
|
||
RecurringPayment,
|
||
RecurringPaymentTransactionLink,
|
||
Tag,
|
||
Transaction,
|
||
User,
|
||
)
|
||
|
||
|
||
class UserForm(forms.ModelForm):
|
||
password = ReadOnlyPasswordHashField(
|
||
help_text=(
|
||
"Raw passwords are not stored, "
|
||
"so there is no way to see this user’s password, "
|
||
"but you can change the password using "
|
||
"<a href='../password/'>this form</a>."
|
||
)
|
||
)
|
||
|
||
class Meta:
|
||
fields = "__all__"
|
||
model = User
|
||
|
||
|
||
class UserAdminConfig(UserAdmin):
|
||
form = UserForm
|
||
|
||
search_fields = ("username", "id",)
|
||
readonly_fields = (
|
||
"id",
|
||
"date_joined",
|
||
"last_login",
|
||
"last_updated",
|
||
)
|
||
list_filter = ("is_staff", "is_superuser", "is_active")
|
||
ordering = ("-date_joined",)
|
||
list_display = ("username", "name", "last_login", "is_active", "is_superuser")
|
||
fieldsets = (
|
||
(
|
||
"Identifiers",
|
||
{"fields": ("id", "name", "username", "password",)},
|
||
),
|
||
(
|
||
"Personal",
|
||
{
|
||
"fields": (
|
||
"last_login",
|
||
"last_updated",
|
||
"date_joined",
|
||
)
|
||
},
|
||
),
|
||
(
|
||
"Permissions",
|
||
{
|
||
"fields": (
|
||
"is_active",
|
||
"is_staff",
|
||
"is_superuser",
|
||
"groups",
|
||
"user_permissions",
|
||
)
|
||
},
|
||
),
|
||
)
|
||
add_fieldsets = (
|
||
(
|
||
None,
|
||
{
|
||
"classes": ("wide",),
|
||
"fields": (
|
||
"username",
|
||
"password1",
|
||
"password2",
|
||
),
|
||
},
|
||
),
|
||
)
|
||
|
||
|
||
class TransactionConfig(admin.ModelAdmin):
|
||
list_display = (
|
||
"from_account",
|
||
"created_at",
|
||
)
|
||
|
||
|
||
# Register your models here.
|
||
admin.site.register(User, UserAdminConfig)
|
||
admin.site.register(Tag)
|
||
admin.site.register(Bank)
|
||
admin.site.register(Account)
|
||
admin.site.register(RecurringPayment)
|
||
admin.site.register(Transaction, TransactionConfig)
|
||
admin.site.register(RecurringPaymentTransactionLink)
|
||
|