summaryrefslogtreecommitdiff
path: root/app/publications/admin.py
blob: c9c30baccd81632973529254588a3e551fc296cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from django.contrib import admin
from utils.widgets import LGEntryForm

from .models import Publication, Editor, Pitch, Section, PitchIdea


@admin.register(Publication)
class PublicationAdmin(admin.ModelAdmin):
    form = LGEntryForm
    list_display = ('name', 'status')
    list_filter = ('status',)
    search_fields = ['name']
    fieldsets = (
        ('', {
            'fields': ('name', 'url', 'notes', 'section', 'status'),
            'classes': ('show', 'extrapretty', 'wide')
        }),
    )


@admin.register(Editor)
class EditorAdmin(admin.ModelAdmin):
    list_display = ('last_name', 'first_name', 'publication', 'sections')
    list_filter = ('publication', 'section')
    search_fields = ['first_name', 'last_name', 'publication__name', 'section']
    filter_horizontal = ('section',)

    def sections(self, obj):
        return [section for section in obj.section.all()]
    sections.boolean = False

    fieldsets = (
        ('', {
            'fields': ('first_name', 'last_name', 'email', 'publication', 'section', 'notes', 'phone', 'twitter'),
            'classes': ('show', 'extrapretty', 'wide')
        }),
    )


@admin.register(Pitch)
class PitchAdmin(admin.ModelAdmin):
    list_display = ('title', 'date_sent', 'accepted', 'editor', 'publication')
    list_filter = ('editor__publication', 'editor__section')

    def publication(self, obj):
        return obj.editor.publication
    publication.boolean = False

    fieldsets = (
        ('', {
            'fields': ('title', 'pitch', 'editor', 'accepted', 'date_sent'),
            'classes': ('show', 'extrapretty', 'wide')
        }),
    )


@admin.register(PitchIdea)
class PitchIdeaAdmin(admin.ModelAdmin):
    list_display = ('title', )

    fieldsets = (
        ('', {
            'fields': ('title', 'pitch', 'publication'),
            'classes': ('show', 'extrapretty', 'wide')
        }),
    )


@admin.register(Section)
class SectionAdmin(admin.ModelAdmin):
    list_display = ('name',)
    fieldsets = (
        ('', {
            'fields': ('name',),
            'classes': ('show', 'extrapretty', 'wide')
        }),
    )