bornhack-website/src/tickets/admin.py

78 lines
1.9 KiB
Python
Raw Normal View History

2017-08-17 15:51:24 +00:00
from django.contrib import admin
from shop.models import OrderProductRelation
from .models import DiscountTicket, ShopTicket, SponsorTicket, TicketType
2017-08-17 15:51:24 +00:00
class BaseTicketAdmin(admin.ModelAdmin):
2019-06-16 12:32:24 +00:00
actions = ["generate_pdf"]
exclude = ["qrcode_base64"]
2020-02-07 17:46:34 +00:00
readonly_fields = ["token", "badge_token"]
2017-08-17 15:51:24 +00:00
def generate_pdf(self, request, queryset):
for ticket in queryset.all():
ticket.generate_pdf()
2019-06-16 12:32:24 +00:00
generate_pdf.description = "Generate PDF for the ticket"
2017-08-17 15:51:24 +00:00
@admin.register(TicketType)
class TicketTypeAdmin(admin.ModelAdmin):
2019-06-16 12:32:24 +00:00
list_display = ["name", "camp"]
2017-08-19 23:01:44 +00:00
2019-06-16 12:32:24 +00:00
list_filter = ["name", "camp"]
2017-08-17 15:51:24 +00:00
@admin.register(SponsorTicket)
class SponsorTicketAdmin(BaseTicketAdmin):
list_display = ["pk", "ticket_type", "sponsor", "used"]
2017-08-19 23:01:44 +00:00
list_filter = ["ticket_type__camp", "used", "ticket_type", "sponsor"]
2017-08-17 15:51:24 +00:00
2019-06-16 12:32:24 +00:00
search_fields = ["pk", "sponsor__name"]
2017-08-22 17:36:24 +00:00
2017-08-17 15:51:24 +00:00
@admin.register(DiscountTicket)
class DiscountTicketAdmin(BaseTicketAdmin):
pass
@admin.register(ShopTicket)
class ShopTicketAdmin(BaseTicketAdmin):
2017-08-22 17:59:26 +00:00
def user_email(self, obj):
return obj.order.user.email
2017-08-22 18:02:17 +00:00
def is_paid(self, obj):
return obj.order.paid
2017-08-19 23:01:44 +00:00
list_display = [
2019-06-16 12:32:24 +00:00
"pk",
"user_email",
"is_paid",
"ticket_type",
"order",
"product",
"used",
"product_quantity",
2017-08-19 23:01:44 +00:00
]
list_filter = ["ticket_type__camp", "used", "ticket_type", "order", "product"]
2017-08-19 23:01:44 +00:00
2019-06-16 12:32:24 +00:00
search_fields = ["uuid", "order__id", "order__user__email", "name", "email"]
2018-08-17 09:59:28 +00:00
def product_quantity(self, ticket):
orp = OrderProductRelation.objects.get(
product=ticket.product, order=ticket.order
)
return (
str(orp.quantity) if ticket.ticket_type.single_ticket_per_product else "1"
)
product_quantity.short_description = "Quantity"
2018-08-17 09:59:28 +00:00
class ShopTicketInline(admin.TabularInline):
model = ShopTicket