-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathadmin.py
More file actions
49 lines (34 loc) · 1.43 KB
/
admin.py
File metadata and controls
49 lines (34 loc) · 1.43 KB
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
from django.contrib import admin
from django.contrib.admin import StackedInline
from django.utils.safestring import mark_safe
from ordered_model.admin import OrderedModelAdmin
from pythonpro.modules.models import Section, Module, Chapter, Topic
class BaseAdmin(OrderedModelAdmin):
prepopulated_fields = {'slug': ('title',)}
view_on_site = True
def page_link(self, content):
return mark_safe(f'<a href="{content.get_absolute_url()}">See on Page</a>')
page_link.short_description = 'page'
@admin.register(Module)
class ModuleAdmin(BaseAdmin):
list_display = 'title slug order move_up_down_links page_link'.split()
prepopulated_fields = {'slug': ('title',)}
@admin.register(Section)
class SectionAdmin(BaseAdmin):
list_display = 'title slug module order move_up_down_links page_link'.split()
prepopulated_fields = {'slug': ('title',)}
class TopicInline(StackedInline):
model = Topic
prepopulated_fields = {'slug': ('title',)}
extra = 1
ordering = ('order',)
@admin.register(Chapter)
class ChapterAdmin(BaseAdmin):
inlines = [TopicInline]
list_display = 'title slug section order move_up_down_links page_link'.split()
prepopulated_fields = {'slug': ('title',)}
@admin.register(Topic)
class TopicAdmin(BaseAdmin):
list_display = 'title slug chapter order move_up_down_links page_link memberkit_url'.split()
list_filter = ('chapter',)
prepopulated_fields = {'slug': ('title',)}