admin.py 936 Bytes
Newer Older
Arnaud Fabre's avatar
Arnaud Fabre committed
1
2
3
4
5
6
from django.contrib import admin

from .models import Position


def publish_positions(modeladmin, request, queryset):
Jamesie Pic's avatar
Quality    
Jamesie Pic committed
7
    """Set published to True for the queryset"""
Arnaud Fabre's avatar
Arnaud Fabre committed
8
9
10
11
12
13
    queryset.update(published=True)

publish_positions.short_description = 'Publish selected positions'


def unpublish_positions(modeladmin, request, queryset):
Jamesie Pic's avatar
Quality    
Jamesie Pic committed
14
    """Set published to False for the queryset"""
Arnaud Fabre's avatar
Arnaud Fabre committed
15
16
17
18
19
20
    queryset.update(published=False)

unpublish_positions.short_description = 'Unpublish selected positions'


class PositionAdmin(admin.ModelAdmin):
Jamesie Pic's avatar
Quality    
Jamesie Pic committed
21
22
    list_display = (
        'representative',
23
24
        'kind',
        'short_title',
Jamesie Pic's avatar
Quality    
Jamesie Pic committed
25
        'short_text',
26
        'score',
Jamesie Pic's avatar
Quality    
Jamesie Pic committed
27
28
29
        'datetime',
        'link',
        'published')
30
    list_display_links = ('short_title', 'short_text')
Arnaud Fabre's avatar
Arnaud Fabre committed
31
32
33
34
35
    list_editable = ('published',)
    list_filter = ('published',)
    actions = (publish_positions, unpublish_positions)

admin.site.register(Position, PositionAdmin)