From 5172f748454d15c66cf97c8e9986a98d67365930 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Tue, 16 Jul 2019 14:38:52 +0200 Subject: [PATCH] Move aliases to inline admin --- note/admin.py | 42 +++++++++++++++++++--- note/locale/fr/LC_MESSAGES/django.po | 2 +- note/migrations/0002_auto_20190716_1406.py | 18 ++++++++++ note/models/notes.py | 2 +- 4 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 note/migrations/0002_auto_20190716_1406.py diff --git a/note/admin.py b/note/admin.py index 7d82658d..8b786666 100644 --- a/note/admin.py +++ b/note/admin.py @@ -2,8 +2,42 @@ from django.contrib import admin from .models.notes import Alias, NoteClub, NoteSpecial, NoteUser + +class AliasInlines(admin.TabularInline): + """ + Define user and club aliases when editing their note + """ + extra = 0 + model = Alias + + +class NoteClubAdmin(admin.ModelAdmin): + """ + Admin customisation for NoteClub + """ + inlines = (AliasInlines,) + list_display = ('club', 'balance', 'is_active') + + +class NoteSpecialAdmin(admin.ModelAdmin): + """ + Admin customisation for NoteSpecial + """ + list_display = ('special_type', 'balance', 'is_active') + + +class NoteUserAdmin(admin.ModelAdmin): + """ + Admin customisation for NoteUser + """ + inlines = (AliasInlines,) + list_display = ('user', 'balance', 'is_active') + + # Organize note by registration date + date_hierarchy = 'user__date_joined' + + # Register your models here. -admin.site.register(Alias) -admin.site.register(NoteClub) -admin.site.register(NoteSpecial) -admin.site.register(NoteUser) +admin.site.register(NoteClub, NoteClubAdmin) +admin.site.register(NoteSpecial, NoteSpecialAdmin) +admin.site.register(NoteUser, NoteUserAdmin) diff --git a/note/locale/fr/LC_MESSAGES/django.po b/note/locale/fr/LC_MESSAGES/django.po index a4c4bfb6..5616c6db 100644 --- a/note/locale/fr/LC_MESSAGES/django.po +++ b/note/locale/fr/LC_MESSAGES/django.po @@ -71,7 +71,7 @@ msgstr "note spéciale" #: models/notes.py:85 msgid "special notes" -msgstr "notes spéciale" +msgstr "notes spéciales" #: models/notes.py:93 models/transactions.py:18 msgid "name" diff --git a/note/migrations/0002_auto_20190716_1406.py b/note/migrations/0002_auto_20190716_1406.py new file mode 100644 index 00000000..399205aa --- /dev/null +++ b/note/migrations/0002_auto_20190716_1406.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.3 on 2019-07-16 12:06 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('note', '0001_initial'), + ] + + operations = [ + migrations.RenameField( + model_name='noteclub', + old_name='user', + new_name='club', + ), + ] diff --git a/note/models/notes.py b/note/models/notes.py index 2c91d1c5..ce2d3ec1 100644 --- a/note/models/notes.py +++ b/note/models/notes.py @@ -54,7 +54,7 @@ class NoteClub(Note): """ A Note associated to a Club """ - user = models.OneToOneField( + club = models.OneToOneField( 'member.Club', on_delete=models.PROTECT, related_name='note',