-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathadmin.py
More file actions
38 lines (27 loc) · 996 Bytes
/
admin.py
File metadata and controls
38 lines (27 loc) · 996 Bytes
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
from django.contrib import admin
from django.utils.safestring import mark_safe
from pythonpro.cohorts.models import Cohort, LiveClass, Webinar
class ClassInline(admin.StackedInline):
extra = 1
model = LiveClass
ordering = ('start',)
class StudentInline(admin.TabularInline):
readonly_fields = ('added',)
extra = 1
autocomplete_fields = ['user']
model = Cohort.students.through
ordering = ('added',)
class WebinarInline(admin.StackedInline):
extra = 1
model = Webinar
ordering = ('start',)
prepopulated_fields = {'slug': ('title',)}
@admin.register(Cohort)
class CohortAdmin(admin.ModelAdmin):
inlines = [ClassInline, WebinarInline, StudentInline]
prepopulated_fields = {'slug': ('title',)}
list_display = 'title start end page_link'.split()
ordering = ('-start',)
def page_link(self, cohort):
return mark_safe(f'<a href="{cohort.get_absolute_url()}">See on Page</a>')
page_link.short_description = 'page'