3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-11-05 17:36:28 +00:00
coope/users/admin.py

49 lines
1.8 KiB
Python
Raw Normal View History

2018-08-31 12:46:35 +00:00
from django.contrib import admin
2018-11-22 21:52:15 +00:00
from django.contrib.auth.models import Permission
2018-11-27 08:07:12 +00:00
from simple_history.admin import SimpleHistoryAdmin
2019-02-27 07:59:41 +00:00
from django.db.models import F
from .models import School, Profile, CotisationHistory, WhiteListHistory
class CotisationHistoryAdmin(SimpleHistoryAdmin):
list_display = ('user', 'amount', 'duration', 'paymentDate', 'endDate', 'paymentMethod')
ordering = ('user', 'amount', 'duration', 'paymentDate', 'endDate')
search_fields = ('user',)
list_filter = ('paymentMethod', )
class BalanceFilter(admin.SimpleListFilter):
title = 'Solde'
parameter_name = 'solde'
def lookups(self, request, model_admin):
return (
('po', '>0'),
('nu', '=0'),
('ne', '<0'),
)
def queryset(self, request, queryset):
if self.value() == 'po':
return queryset.filter(credit__gt=F('debit'))
elif self.value() == 'nu':
return queryset.filter(credit=F('debit'))
elif self.value() == 'ne':
return queryset.filter(credit__lt=F('debit'))
2018-08-31 12:46:35 +00:00
2018-12-23 20:48:49 +00:00
class ProfileAdmin(SimpleHistoryAdmin):
2019-02-27 07:59:41 +00:00
list_display = ('user', 'credit', 'debit', 'balance', 'school', 'cotisationEnd', 'is_adherent')
ordering = ('user', '-credit', '-debit')
search_fields = ('user',)
list_filter = ('school', BalanceFilter)
class WhiteListHistoryAdmin(SimpleHistoryAdmin):
list_display = ('user', 'paymentDate', 'endDate', 'duration')
ordering = ('user', 'duration', 'paymentDate', 'endDate')
search_fields = ('user',)
2018-12-23 20:48:49 +00:00
2018-11-27 08:07:12 +00:00
admin.site.register(Permission, SimpleHistoryAdmin)
admin.site.register(School, SimpleHistoryAdmin)
2019-02-27 07:59:41 +00:00
admin.site.register(WhiteListHistory, WhiteListHistoryAdmin)
2018-12-23 20:48:49 +00:00
admin.site.register(Profile, ProfileAdmin)
2019-02-27 07:59:41 +00:00
admin.site.register(CotisationHistory, CotisationHistoryAdmin)