bornhack-website/shop/admin.py

112 lines
2.4 KiB
Python
Raw Normal View History

2016-06-19 06:43:56 +00:00
from django.contrib import admin
from . import models
admin.site.register(models.EpayCallback)
admin.site.register(models.EpayPayment)
2016-05-29 10:54:02 +00:00
admin.site.register(models.CoinifyAPIInvoice)
admin.site.register(models.CoinifyAPICallback)
2016-05-29 10:54:02 +00:00
admin.site.register(models.Invoice)
2016-06-18 18:51:53 +00:00
admin.site.register(models.CreditNote)
2016-07-12 20:42:30 +00:00
admin.site.register(models.CustomOrder)
2016-05-31 21:23:05 +00:00
@admin.register(models.ProductCategory)
class ProductCategoryAdmin(admin.ModelAdmin):
list_display = [
'name',
]
@admin.register(models.Product)
class ProductAdmin(admin.ModelAdmin):
list_display = [
'name',
'category',
'price',
'available_in',
]
class ProductInline(admin.TabularInline):
model = models.OrderProductRelation
class TicketInline(admin.TabularInline):
model = models.Ticket
exclude = ['qrcode_base64']
@admin.register(models.Order)
class OrderAdmin(admin.ModelAdmin):
2016-05-31 21:23:05 +00:00
change_form_template = 'admin/change_order_form.html'
readonly_fields = ('paid',)
2016-06-04 07:46:10 +00:00
def get_email(self, obj):
return obj.user.email
list_display = [
2016-05-31 20:15:56 +00:00
'id',
'user',
2016-06-04 07:46:10 +00:00
'get_email',
'total',
'payment_method',
'open',
'paid',
2016-06-01 09:10:06 +00:00
'cancelled',
'refunded',
]
list_filter = [
'camp',
'payment_method',
'open',
'paid',
'cancelled',
'refunded',
2016-06-18 18:51:53 +00:00
'user',
]
exclude = ['products']
inlines = [ProductInline, TicketInline]
actions = ['mark_order_as_paid', 'mark_order_as_refunded']
def mark_order_as_paid(self, request, queryset):
for order in queryset.filter(paid=False):
order.mark_as_paid()
mark_order_as_paid.description = 'Mark order(s) as paid'
def mark_order_as_refunded(self, request, queryset):
for order in queryset.filter(refunded=False):
2016-06-19 06:49:30 +00:00
order.mark_as_refunded(request)
mark_order_as_refunded.description = 'Mark order(s) as refunded'
2016-08-27 08:29:26 +00:00
def get_user_email(obj):
return obj.order.user.email
@admin.register(models.Ticket)
class TicketModelAdmin(admin.ModelAdmin):
2016-08-27 08:29:26 +00:00
list_display = [
'order',
'product',
'name',
'email',
get_user_email,
'get_token',
'checked_in'
]
2016-08-27 10:29:51 +00:00
list_filter = ['product', 'checked_in']
2016-08-27 08:40:57 +00:00
actions = ['mark_as_arrived']
def mark_as_arrived(self, request, queryset):
queryset.update(checked_in=True)