diff --git a/apps/note/admin.py b/apps/note/admin.py index 0aa3be39..f403dcd1 100644 --- a/apps/note/admin.py +++ b/apps/note/admin.py @@ -7,7 +7,7 @@ from polymorphic.admin import PolymorphicChildModelAdmin, \ PolymorphicChildModelFilter, PolymorphicParentModelAdmin from .models.notes import Alias, Note, NoteClub, NoteSpecial, NoteUser -from .models.transactions import Transaction, TransactionCategory, TransactionTemplate +from .models.transactions import Transaction, TransactionCategory, TransactionTemplate, TransactionType class AliasInlines(admin.TabularInline): @@ -161,3 +161,11 @@ class TransactionCategoryAdmin(admin.ModelAdmin): """ list_display = ('name', ) list_filter = ('name', ) + +@admin.register(TransactionType) +class TransactionTypeAdmin(admin.ModelAdmin): + """ + Admin customisation for TransactionTemplate + """ + list_display = ('name', ) + list_filter = ('name', ) diff --git a/apps/note/models/__init__.py b/apps/note/models/__init__.py index 7e6cc310..e372fc46 100644 --- a/apps/note/models/__init__.py +++ b/apps/note/models/__init__.py @@ -3,11 +3,11 @@ from .notes import Alias, Note, NoteClub, NoteSpecial, NoteUser from .transactions import MembershipTransaction, Transaction, \ - TransactionCategory, TransactionTemplate + TransactionCategory, TransactionTemplate, TransactionType __all__ = [ # Notes 'Alias', 'Note', 'NoteClub', 'NoteSpecial', 'NoteUser', # Transactions - 'MembershipTransaction', 'Transaction', 'TransactionCategory', 'TransactionTemplate', + 'MembershipTransaction', 'Transaction', 'TransactionCategory', 'TransactionTemplate','TransactionType', ] diff --git a/apps/note/models/transactions.py b/apps/note/models/transactions.py index 043cbbe9..d441785e 100644 --- a/apps/note/models/transactions.py +++ b/apps/note/models/transactions.py @@ -76,6 +76,26 @@ class TransactionTemplate(models.Model): return reverse('note:template_update', args=(self.pk, )) +class TransactionType(models.Model): + """ + Defined a recurrent transaction category + + Example: food, softs, ... + """ + name = models.CharField( + verbose_name=_("name"), + max_length=31, + unique=True, + ) + + class Meta: + verbose_name = _("transaction type") + verbose_name_plural = _("transaction types") + + def __str__(self): + return str(self.name) + + class Transaction(models.Model): """ General transaction between two :model:`note.Note` @@ -107,7 +127,9 @@ class Transaction(models.Model): default=1, ) amount = models.PositiveIntegerField(verbose_name=_('amount'), ) - transaction_type = models.CharField( + transaction_type = models.ForeignKey( + TransactionType, + on_delete=models.PROTECT, verbose_name=_('type'), max_length=31, )