1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.utils.translation import ugettext_lazy as _
6 from django.contrib import admin
7 from .models import Offer, Perk, Funding, Spent
10 class OfferAdmin(admin.ModelAdmin):
12 list_display = ['title', 'author', 'target', 'sum', 'is_win', 'start', 'end']
13 search_fields = ['title', 'author']
14 readonly_fields = ('cover_img_tag',)
17 class PerkAdmin(admin.ModelAdmin):
19 search_fields = ['name', 'long_name']
20 list_display = ['name', 'long_name', 'price', 'end_date', 'offer']
21 list_filter = ['offer']
24 class PayedFilter(admin.SimpleListFilter):
25 title = _('payment complete')
26 parameter_name = 'payed'
28 def lookups(self, request, model_admin):
34 def queryset(self, request, queryset):
35 if self.value() == 'yes':
36 return queryset.exclude(payed_at=None)
37 elif self.value() == 'no':
38 return queryset.filter(payed_at=None)
41 class PerksFilter(admin.SimpleListFilter):
43 parameter_name = 'perks'
45 def lookups(self, request, model_admin):
51 def queryset(self, request, queryset):
52 if self.value() == 'yes':
53 return queryset.exclude(perks=None)
54 elif self.value() == 'no':
55 return queryset.filter(perks=None)
58 class FundingAdmin(admin.ModelAdmin):
60 list_display = ['payed_at', 'offer', 'amount', 'name', 'email', 'perk_names']
61 search_fields = ['name', 'email', 'offer__title', 'offer__author']
62 list_filter = [PayedFilter, 'offer', PerksFilter]
65 class SpentAdmin(admin.ModelAdmin):
67 list_display = ['book', 'amount', 'timestamp']
68 search_fields = ['book__title']
71 admin.site.register(Offer, OfferAdmin)
72 admin.site.register(Perk, PerkAdmin)
73 admin.site.register(Funding, FundingAdmin)
74 admin.site.register(Spent, SpentAdmin)