from django.contrib import admin

# Register your models here.
from django.urls import reverse
from django.utils.html import format_html

from assignments.models import Assignment, StudentSubmission, SubmissionFeedback


class StudentSubmissionInline(admin.TabularInline):
    model = StudentSubmission

    readonly_fields = ('link', 'document', 'student', 'final',)
    exclude = ('text',)
    extra = 0

    def link(self, obj):
        return format_html('<a href={}>{}</a>'.format(reverse('admin:assignments_studentsubmission_change', args=(obj.id,)), obj.text))

@admin.register(Assignment)
class AssignmentAdmin(admin.ModelAdmin):
    list_display = ('title', 'module', 'deleted', 'owner', )
    autocomplete_fields = ('owner',)

    inlines = [
        StudentSubmissionInline
    ]


@admin.register(StudentSubmission)
class StudentSubmissionAdmin(admin.ModelAdmin):
    pass

@admin.register(SubmissionFeedback)
class SubmissionFeedbackAdmin(admin.ModelAdmin):
    pass

