1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from django.utils.translation import ugettext_lazy as _
5 from django.contrib import admin
6 from .models import Offer, Perk, Funding, Spent
9 class OfferAdmin(admin.ModelAdmin):
11 list_display = ['title', 'author', 'target', 'sum', 'is_win', 'start', 'end']
12 search_fields = ['title', 'author']
13 readonly_fields = ('cover_img_tag',)
16 class PerkAdmin(admin.ModelAdmin):
18 search_fields = ['name', 'long_name']
19 list_display = ['name', 'long_name', 'price', 'end_date', 'offer']
20 list_filter = ['offer']
23 class PayedFilter(admin.SimpleListFilter):
24 title = _('payment complete')
25 parameter_name = 'payed'
27 def lookups(self, request, model_admin):
33 def queryset(self, request, queryset):
34 if self.value() == 'yes':
35 return queryset.exclude(payed_at=None)
36 elif self.value() == 'no':
37 return queryset.filter(payed_at=None)
40 class PerksFilter(admin.SimpleListFilter):
42 parameter_name = 'perks'
44 def lookups(self, request, model_admin):
50 def queryset(self, request, queryset):
51 if self.value() == 'yes':
52 return queryset.exclude(perks=None)
53 elif self.value() == 'no':
54 return queryset.filter(perks=None)
57 class FundingAdmin(admin.ModelAdmin):
59 list_display = ['payed_at', 'offer', 'amount', 'name', 'email', 'perk_names']
60 search_fields = ['name', 'email', 'offer__title', 'offer__author']
61 list_filter = [PayedFilter, 'offer', PerksFilter]
64 class SpentAdmin(admin.ModelAdmin):
66 list_display = ['book', 'amount', 'timestamp']
67 search_fields = ['book__title']
70 admin.site.register(Offer, OfferAdmin)
71 admin.site.register(Perk, PerkAdmin)
72 admin.site.register(Funding, FundingAdmin)
73 admin.site.register(Spent, SpentAdmin)