admin.py 2.32 KB
Newer Older
1
from django.contrib import admin
2
from django.utils.translation import gettext_lazy as _
3

4
5
from partners.models import (Partner, PartnerEvent, PartnerImage,
                             Vacancy, VacancyCategory)
6
7
from utils.translation import TranslatedModelAdmin

8
9

class PartnerImageInline(admin.StackedInline):
10
11
    """Class to show partner images inline in the admin."""

12
13
14
15
16
    model = PartnerImage


@admin.register(Partner)
class PartnerAdmin(admin.ModelAdmin):
17
18
    """Class to show partners in the admin."""

19
    prepopulated_fields = {'slug': ('name',)}
20
21
    list_display = ('name', 'is_active', 'is_main_partner',
                    'is_local_partner')
22
    search_fields = ('name', 'city')
23
    list_filter = ('is_active',)
24
    inlines = (PartnerImageInline,)
25
26
27
28

    fieldsets = (
        (None, {
            'fields': (
29
30
31
                'name', 'slug', 'link',
                'company_profile', 'logo', 'site_header',
                'is_active', 'is_main_partner', 'is_local_partner',
32
33
            )
        }),
34
        (_('Address'), {
35
36
37
38
39
            'fields': ('address', 'zip_code', 'city')

        }),
    )

40
41
42

@admin.register(VacancyCategory)
class VacancyCategoryAdmin(TranslatedModelAdmin):
43
44
    """Class to show vacancy categories in the admin."""

45
    prepopulated_fields = {'slug': ('name_en',)}
46
    fields = ['name', 'slug']
47
48
49
50


@admin.register(Vacancy)
class VacancyAdmin(admin.ModelAdmin):
51
52
    """Class to show vacancies in the admin."""

53
    list_display = ('title', 'partner', 'company_name')
54
    search_fields = ('title', 'partner__name', 'company_name',)
55
56
    fieldsets = (
        (None, {
57
            'fields': ('title', 'description', 'link',)
58
        }),
59
        (_('Existing partner'), {
60
61
            'fields': ('partner',)
        }),
62
        (_('Other partner'), {
63
64
            'fields': ('company_name', 'company_logo',)
        }),
65
        (_('Categories'), {
66
            'fields': ('categories',)
Joris's avatar
Joris committed
67
        })
68
    )
69
70
71
72


@admin.register(PartnerEvent)
class PartnerEventAdmin(TranslatedModelAdmin):
73
74
    """Class to show partner events in the admin."""

75
76
    fields = ('partner', 'other_partner', 'title', 'description', 'location',
              'start', 'end', 'url', 'published')
77
78
79
    list_display = ('title', 'start', 'end',
                    'partner', 'published')
    list_filter = ('start', 'published')
80
    search_fields = ('title', 'partner__name')