from django.contrib import admin

# Register your models here.

from .models import Course
from .models import Section
from .models import Slide


# in case the ORM is registered directly all fields will be shown
#admin.site.register(Course)


class SlideInline(admin.StackedInline):
    model = Slide
    extra = 3

class SectionInline(admin.TabularInline):
    model = Section
    extra = 3


class SectionsInline(admin.TabularInline):
    model = Course.sections.through

class SlidesInline(admin.TabularInline):
    model = Section.slides.through



class SectionAdmin(admin.ModelAdmin):
    inlines = [
        SlidesInline,
    ]
    exclude = ('slides',)

# otherwise "fields" serves as a whitelist
class CourseAdmin(admin.ModelAdmin):
    #fieldsets = [
    #        (None, {'fields': ['title', 'description', 'source_path']}),
    #]
    #inlines = [SectionInline]
    inlines = [
        SectionsInline,
    ]
    exclude = ('sections',)



# otherwise "fields" serves as a whitelist
#class SectionAdmin(admin.ModelAdmin):
#    #list_display = ('title')
#    fieldsets = [
#            (None, {'fields': ['title', 'description']}),
#          #  ("Meta", {'fields': ['pub_date'], 'classes': ['collapse']}),
#    ]
#    #inlines = [SlideInline]


class SlideAdmin(admin.ModelAdmin):
    list_display = ('title', 'description')



admin.site.register(Course, CourseAdmin)
admin.site.register(Section, SectionAdmin)
admin.site.register(Slide, SlideAdmin)

# Use django default admin
#admin.site.register(Course)
#admin.site.register(Section)
#admin.site.register(Slide)



