admin.py 1.23 KB
Newer Older
1
from django.contrib import admin
Thom Wiggers's avatar
Thom Wiggers committed
2
from django.urls import reverse
3
from django.utils import timezone
4
5
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _
6
7

from .models import Order, PizzaEvent, Product
8
from events.models import Event
9

10
11
12
13

@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    list_display = ('name', 'price', 'available')
14
    list_filter = ('available', 'restricted')
15
16
17
18
19


@admin.register(PizzaEvent)
class PizzaEventAdmin(admin.ModelAdmin):
    list_display = ('title', 'orders')
20
    exclude = ('end_reminder',)
21
22
23
24
25
26

    def orders(self, obj):
        return format_html(_('<strong><a href="{link}">Orders</a></strong>'),
                           link=reverse('pizzas:orders',
                                        kwargs={'event_pk': obj.pk}))

27
28
29
30
31
32
33
    def formfield_for_foreignkey(self, db_field, request, **kwargs):
        if db_field.name == "event":
            kwargs["queryset"] = Event.objects.filter(
                end__gte=timezone.now())
        return super(PizzaEventAdmin, self).formfield_for_foreignkey(
            db_field, request, **kwargs)

34
35
36
37

@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
    list_display = ('pizza_event', 'member_name', 'product', 'paid')