-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin.py
executable file
·47 lines (37 loc) · 1.36 KB
/
admin.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.contrib import admin
from fgallery.models import Album, Photo
from fgallery.forms import PhotoForm
class PhotoInline(admin.TabularInline):
model = Photo
form = PhotoForm
class AlbumAdmin(admin.ModelAdmin):
date_hierarchy = "publish"
list_per_page = 20
list_display = ["title", "publish", "is_published"]
list_editable = ["is_published"]
actions = ["make_published"]
inlines = [PhotoInline,]
def save_model(self, request, obj, form, change):
if not change:
obj.author = request.user
obj.save()
def make_published(self, request, queryset):
queryset.update(is_published=True)
make_published.short_description = "Mark selected entries as published"
class PhotoAdmin(admin.ModelAdmin):
date_hierarchy = "publish"
list_per_page = 20
list_display = ["title", "publish", "is_published"]
list_editable = ["is_published"]
actions = ["make_published"]
def save_model(self, request, obj, form, change):
if not change:
obj.author = request.user
obj.save()
def make_published(self, request, queryset):
queryset.update(is_published=True)
make_published.short_description = "Mark selected entries as published"
admin.site.register(Album, AlbumAdmin)
admin.site.register(Photo, PhotoAdmin)