This repository has been archived by the owner on Jun 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.py
82 lines (75 loc) · 3.01 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
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
78
79
80
81
82
# -*- coding: utf-8 -*-
from django.contrib import admin
from django.db import models
from book.models import Chapter, UserChapter
from tinymce.widgets import TinyMCE
class ChapterAdmin(admin.ModelAdmin):
fieldsets = (
(None, {
'fields': ('title', 'summary_html', 'body_html', 'user_created', 'visible', 'picture','picture_description','tags_string')
}),
('Meta', {
'fields': ('author', 'pub_date', 'mod_date', 'index')
}),
('Html version (do not change it)', {
'classes': ('collapse',),
'fields': ('summary', 'body')
}),
)
list_display = ('title', 'pub_date', 'mod_date', 'index','visible','user_created')
list_filter = ['pub_date', 'mod_date']
formfield_overrides = {
models.TextField: {'widget': TinyMCE(attrs={'cols': 80, 'rows': 20}, )},
}
js = (
'js/tiny_mce/tiny_mce.js',
)
class UserChapterAdmin(admin.ModelAdmin):
fieldsets = (
(None, {
'fields': ('title', 'summary_html', 'body_html', 'picture','picture_description','tags_string')
}),
('Meta', {
'fields': ('author', 'pub_date', 'index')
}),
('Html version (do not change it)', {
'classes': ('collapse',),
'fields': ('summary', 'body')
}),
)
list_display = ('title', 'pub_date', 'index')
list_filter = ['pub_date']
formfield_overrides = {
models.TextField: {'widget': TinyMCE(attrs={'cols': 80, 'rows': 20}, )},
}
js = (
'js/tiny_mce/tiny_mce.js',
)
def make_chapter_public(self, request, queryset):
from django.db.models import Max
antal=0
for userchapter in queryset:
highest_index = Chapter.objects.aggregate(Max('index'))
index = highest_index['index__max']+1
chapter = Chapter(title=userchapter.title,
summary=userchapter.summary,
summary_html=userchapter.summary_html,
body=userchapter.body,
body_html=userchapter.body_html,
mod_date=userchapter.pub_date,
pub_date=userchapter.pub_date,
index=index,
author=userchapter.author,
user_created=True,
visible=True,
picture=userchapter.picture,
picture_description=userchapter.picture_description,
tags_string=userchapter.tags_string)
chapter.save()
userchapter.delete()
antal+=1
self.message_user(request, '%s successfully made public.' % antal)
make_chapter_public.short_description = 'Make chapter public'
actions = ['make_chapter_public']
admin.site.register(UserChapter, UserChapterAdmin)
admin.site.register(Chapter, ChapterAdmin)