mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-20 17:41:55 +02:00
💄 Improve Django Admin
This commit is contained in:
@ -4,6 +4,9 @@
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from note.templatetags.pretty_money import pretty_money
|
||||
from note_kfet.admin import admin_site
|
||||
|
||||
from .forms import ProfileForm
|
||||
@ -18,6 +21,7 @@ class ProfileInline(admin.StackedInline):
|
||||
can_delete = False
|
||||
|
||||
|
||||
@admin.register(User, site=admin_site)
|
||||
class CustomUserAdmin(UserAdmin):
|
||||
inlines = (ProfileInline,)
|
||||
list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
|
||||
@ -33,9 +37,33 @@ class CustomUserAdmin(UserAdmin):
|
||||
return super().get_inline_instances(request, obj)
|
||||
|
||||
|
||||
# Update Django User with profile
|
||||
admin_site.register(User, CustomUserAdmin)
|
||||
@admin.register(Club, site=admin_site)
|
||||
class ClubAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'parent_club', 'email', 'require_memberships', 'pretty_fee_paid',
|
||||
'pretty_fee_unpaid', 'membership_start', 'membership_end',)
|
||||
ordering = ('name',)
|
||||
search_fields = ('name', 'email',)
|
||||
|
||||
# Add other models
|
||||
admin_site.register(Club)
|
||||
admin_site.register(Membership)
|
||||
def pretty_fee_paid(self, obj):
|
||||
return pretty_money(obj.membership_fee_paid)
|
||||
|
||||
def pretty_fee_unpaid(self, obj):
|
||||
return pretty_money(obj.membership_fee_unpaid)
|
||||
|
||||
pretty_fee_paid.short_description = _("membership fee (paid students)")
|
||||
pretty_fee_unpaid.short_description = _("membership fee (unpaid students)")
|
||||
|
||||
|
||||
@admin.register(Membership, site=admin_site)
|
||||
class MembershipAdmin(admin.ModelAdmin):
|
||||
list_display = ('user', 'club', 'date_start', 'date_end', 'view_roles', 'pretty_fee',)
|
||||
ordering = ('-date_start', 'club')
|
||||
|
||||
def view_roles(self, obj):
|
||||
return ", ".join(role.name for role in obj.roles.all())
|
||||
|
||||
def pretty_fee(self, obj):
|
||||
return pretty_money(obj.fee)
|
||||
|
||||
view_roles.short_description = _("roles")
|
||||
pretty_fee.short_description = _("fee")
|
||||
|
@ -10,6 +10,7 @@ from note_kfet.admin import admin_site
|
||||
from .models.notes import Alias, Note, NoteClub, NoteSpecial, NoteUser
|
||||
from .models.transactions import Transaction, TemplateCategory, TransactionTemplate, \
|
||||
RecurrentTransaction, MembershipTransaction, SpecialTransaction
|
||||
from .templatetags.pretty_money import pretty_money
|
||||
|
||||
|
||||
class AliasInlines(admin.TabularInline):
|
||||
@ -37,7 +38,7 @@ class NoteAdmin(PolymorphicParentModelAdmin):
|
||||
|
||||
# Organize notes by registration date
|
||||
date_hierarchy = 'created_at'
|
||||
ordering = ['-created_at']
|
||||
ordering = ['name']
|
||||
|
||||
# Search by aliases
|
||||
search_fields = ['alias__name']
|
||||
@ -74,6 +75,18 @@ class NoteSpecialAdmin(PolymorphicChildModelAdmin):
|
||||
"""
|
||||
readonly_fields = ('balance',)
|
||||
|
||||
def has_add_permission(self, request):
|
||||
"""
|
||||
A club note should not be manually added
|
||||
"""
|
||||
return False
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
"""
|
||||
A club note should not be manually removed
|
||||
"""
|
||||
return False
|
||||
|
||||
|
||||
@admin.register(NoteUser, site=admin_site)
|
||||
class NoteUserAdmin(PolymorphicChildModelAdmin):
|
||||
@ -103,11 +116,11 @@ class TransactionAdmin(PolymorphicParentModelAdmin):
|
||||
"""
|
||||
Admin customisation for Transaction
|
||||
"""
|
||||
child_models = (RecurrentTransaction, MembershipTransaction, SpecialTransaction)
|
||||
child_models = (Transaction, RecurrentTransaction, MembershipTransaction, SpecialTransaction)
|
||||
list_display = ('created_at', 'poly_source', 'poly_destination',
|
||||
'quantity', 'amount', 'valid')
|
||||
list_filter = ('valid',)
|
||||
autocomplete_fields = (
|
||||
readonly_fields = (
|
||||
'source',
|
||||
'destination',
|
||||
)
|
||||
@ -146,6 +159,13 @@ class MembershipTransactionAdmin(PolymorphicChildModelAdmin):
|
||||
"""
|
||||
|
||||
|
||||
@admin.register(RecurrentTransaction, site=admin_site)
|
||||
class RecurrentTransactionAdmin(PolymorphicChildModelAdmin):
|
||||
"""
|
||||
Admin customisation for RecurrentTransaction
|
||||
"""
|
||||
|
||||
|
||||
@admin.register(SpecialTransaction, site=admin_site)
|
||||
class SpecialTransactionAdmin(PolymorphicChildModelAdmin):
|
||||
"""
|
||||
@ -158,8 +178,9 @@ class TransactionTemplateAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
Admin customisation for TransactionTemplate
|
||||
"""
|
||||
list_display = ('name', 'poly_destination', 'amount', 'category', 'display',)
|
||||
list_filter = ('category', 'display')
|
||||
list_display = ('name', 'poly_destination', 'pretty_amount', 'category', 'display', 'highlighted',)
|
||||
list_filter = ('category', 'display', 'highlighted',)
|
||||
search_fields = ('name', 'destination__club__name', 'amount',)
|
||||
autocomplete_fields = ('destination',)
|
||||
|
||||
def poly_destination(self, obj):
|
||||
@ -170,6 +191,11 @@ class TransactionTemplateAdmin(admin.ModelAdmin):
|
||||
|
||||
poly_destination.short_description = _('destination')
|
||||
|
||||
def pretty_amount(self, obj):
|
||||
return pretty_money(obj.amount)
|
||||
|
||||
pretty_amount.short_description = _("amount")
|
||||
|
||||
|
||||
@admin.register(TemplateCategory, site=admin_site)
|
||||
class TemplateCategoryAdmin(admin.ModelAdmin):
|
||||
@ -177,4 +203,3 @@ class TemplateCategoryAdmin(admin.ModelAdmin):
|
||||
Admin customisation for TransactionTemplate
|
||||
"""
|
||||
list_display = ('name',)
|
||||
list_filter = ('name',)
|
||||
|
@ -20,7 +20,9 @@ class PermissionAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
Admin customisation for Permission
|
||||
"""
|
||||
list_display = ('type', 'model', 'field', 'mask', 'description', )
|
||||
list_display = ('description', 'type', 'model', 'field', 'mask', )
|
||||
list_filter = ('type', 'mask', 'model',)
|
||||
search_fields = ('description', 'field',)
|
||||
|
||||
|
||||
@admin.register(Role, site=admin_site)
|
||||
|
@ -28,4 +28,15 @@ class RemittanceAdmin(admin.ModelAdmin):
|
||||
return not obj.closed and super().has_change_permission(request, obj)
|
||||
|
||||
|
||||
admin_site.register(SogeCredit)
|
||||
@admin.register(SogeCredit, site=admin_site)
|
||||
class SogeCreditAdmin(admin.ModelAdmin):
|
||||
"""
|
||||
Admin customisation for Remittance
|
||||
"""
|
||||
list_display = ('user', 'valid',)
|
||||
readonly_fields = ('transactions', 'credit_transaction',)
|
||||
|
||||
def has_add_permission(self, request):
|
||||
# Don't create a credit manually
|
||||
return False
|
||||
|
||||
|
Reference in New Issue
Block a user