1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-12-23 07:52:23 +00:00

More models in admin

This commit is contained in:
Alexandre Iooss 2019-07-17 09:49:59 +02:00
parent eed5f4b542
commit 90ffaae2f2
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
2 changed files with 36 additions and 1 deletions

View File

@ -7,7 +7,7 @@ from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from .forms import CustomUserChangeForm
from .models import Club, Profile
from .models import Club, Membership, Profile, Role
class ProfileInline(admin.StackedInline):
@ -33,6 +33,11 @@ class CustomUserAdmin(UserAdmin):
return super().get_inline_instances(request, obj)
# Update Django User with profile
admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)
# Add other models
admin.site.register(Club)
admin.site.register(Membership)
admin.site.register(Role)

View File

@ -26,6 +26,21 @@ class NoteClubAdmin(admin.ModelAdmin):
list_filter = ('is_active',)
search_fields = ['club__name']
# We can't change club after creation
readonly_fields = ('club',)
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
class NoteSpecialAdmin(admin.ModelAdmin):
"""
@ -47,6 +62,21 @@ class NoteUserAdmin(admin.ModelAdmin):
date_hierarchy = 'user__date_joined'
ordering = ['-user__date_joined']
# We can't change user after creation
readonly_fields = ('user',)
def has_add_permission(self, request):
"""
An user note should not be manually added
"""
return False
def has_delete_permission(self, request, obj=None):
"""
An user note should not be manually removed
"""
return False
class TransactionTemplateAdmin(admin.ModelAdmin):
"""