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']
25 class PayedFilter(admin.SimpleListFilter):
26 title = _('payment complete')
27 parameter_name = 'payed'
28 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)
39 class PerksFilter(admin.SimpleListFilter):
41 parameter_name = 'perks'
42 def lookups(self, request, model_admin):
47 def queryset(self, request, queryset):
48 if self.value() == 'yes':
49 return queryset.exclude(perks=None)
50 elif self.value() == 'no':
51 return queryset.filter(perks=None)
54 class FundingAdmin(admin.ModelAdmin):
56 list_display = ['payed_at', 'offer', 'amount', 'name', 'email', 'perk_names']
57 search_fields = ['name', 'email', 'offer__title', 'offer__author']
58 list_filter = [PayedFilter, 'offer', PerksFilter]
62 class SpentAdmin(admin.ModelAdmin):
64 list_display = ['book', 'amount', 'timestamp']
65 search_fields = ['book__title']
68 admin.site.register(Offer, OfferAdmin)
69 admin.site.register(Perk, PerkAdmin)
70 admin.site.register(Funding, FundingAdmin)
71 admin.site.register(Spent, SpentAdmin)