mirror of https://gitlab.crans.org/bde/nk20
Note admin fully implemented
This commit is contained in:
parent
1bfcedd4fe
commit
3a6d39a53d
|
@ -3,8 +3,9 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from polymorphic.admin import PolymorphicParentModelAdmin, \
|
from django.utils.translation import gettext_lazy as _
|
||||||
PolymorphicChildModelAdmin, PolymorphicChildModelFilter
|
from polymorphic.admin import PolymorphicChildModelAdmin, \
|
||||||
|
PolymorphicChildModelFilter, PolymorphicParentModelAdmin
|
||||||
|
|
||||||
from .models.notes import Alias, Note, NoteClub, NoteSpecial, NoteUser
|
from .models.notes import Alias, Note, NoteClub, NoteSpecial, NoteUser
|
||||||
from .models.transactions import MembershipTransaction, Transaction, \
|
from .models.transactions import MembershipTransaction, Transaction, \
|
||||||
|
@ -93,16 +94,46 @@ class NoteUserAdmin(PolymorphicChildModelAdmin):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(Transaction)
|
||||||
|
class TransactionAdmin(admin.ModelAdmin):
|
||||||
|
"""
|
||||||
|
Admin customisation for Transaction
|
||||||
|
"""
|
||||||
|
list_display = ('created_at', 'poly_source', 'poly_destination',
|
||||||
|
'quantity', 'amount', 'transaction_type', 'valid')
|
||||||
|
list_filter = ('transaction_type', 'valid')
|
||||||
|
autocomplete_fields = ('source', 'destination',)
|
||||||
|
|
||||||
|
def poly_source(self, obj):
|
||||||
|
"""
|
||||||
|
Force source to resolve polymorphic object
|
||||||
|
"""
|
||||||
|
return str(obj.source)
|
||||||
|
|
||||||
|
poly_source.short_description = _('source')
|
||||||
|
|
||||||
|
def poly_destination(self, obj):
|
||||||
|
"""
|
||||||
|
Force destination to resolve polymorphic object
|
||||||
|
"""
|
||||||
|
return str(obj.destination)
|
||||||
|
|
||||||
|
poly_destination.short_description = _('destination')
|
||||||
|
|
||||||
|
|
||||||
@admin.register(TransactionTemplate)
|
@admin.register(TransactionTemplate)
|
||||||
class TransactionTemplateAdmin(admin.ModelAdmin):
|
class TransactionTemplateAdmin(admin.ModelAdmin):
|
||||||
"""
|
"""
|
||||||
Admin customisation for TransactionTemplate
|
Admin customisation for TransactionTemplate
|
||||||
"""
|
"""
|
||||||
list_display = ('name', 'destination', 'amount', 'template_type')
|
list_display = ('name', 'poly_destination', 'amount', 'template_type')
|
||||||
list_filter = ('destination', 'template_type',)
|
list_filter = ('template_type',)
|
||||||
# autocomplete_fields = ('destination',)
|
autocomplete_fields = ('destination',)
|
||||||
|
|
||||||
|
def poly_destination(self, obj):
|
||||||
|
"""
|
||||||
|
Force destination to resolve polymorphic object
|
||||||
|
"""
|
||||||
|
return str(obj.destination)
|
||||||
|
|
||||||
# Register other models here.
|
poly_destination.short_description = _('destination')
|
||||||
admin.site.register(MembershipTransaction)
|
|
||||||
admin.site.register(Transaction)
|
|
||||||
|
|
|
@ -51,8 +51,8 @@ class Transaction(models.Model):
|
||||||
related_name='+',
|
related_name='+',
|
||||||
verbose_name=_('destination'),
|
verbose_name=_('destination'),
|
||||||
)
|
)
|
||||||
datetime = models.DateTimeField(
|
created_at = models.DateTimeField(
|
||||||
verbose_name=_('destination'),
|
verbose_name=_('created at'),
|
||||||
default=timezone.now,
|
default=timezone.now,
|
||||||
)
|
)
|
||||||
quantity = models.PositiveSmallIntegerField(
|
quantity = models.PositiveSmallIntegerField(
|
||||||
|
|
Loading…
Reference in New Issue