2023-03-19 13:42:47 +00:00
|
|
|
|
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",
|
|
|
|
|
|
),
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-03-22 11:18:37 +00:00
|
|
|
|
class TransactionConfig(admin.ModelAdmin):
|
|
|
|
|
|
list_display = (
|
|
|
|
|
|
"from_account",
|
|
|
|
|
|
"created_at",
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2023-03-19 13:42:47 +00:00
|
|
|
|
|
|
|
|
|
|
# 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)
|
2023-03-22 11:18:37 +00:00
|
|
|
|
admin.site.register(Transaction, TransactionConfig)
|
2023-03-19 13:42:47 +00:00
|
|
|
|
admin.site.register(RecurringPaymentTransactionLink)
|
|
|
|
|
|
|