initial
This commit is contained in:
73
content/admin.py
Normal file
73
content/admin.py
Normal file
@@ -0,0 +1,73 @@
|
||||
from django.contrib import admin
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from content.models import Link, MediaFile, Question, QuestionVersion, Level, Label
|
||||
from lib.utils import color_label
|
||||
|
||||
|
||||
@admin.register(Level)
|
||||
class LevelAdmin(admin.ModelAdmin):
|
||||
search_fields = ('name', 'value',)
|
||||
list_display = ('name', 'value', 'color')
|
||||
list_editable = ('color',)
|
||||
|
||||
|
||||
@admin.register(Label)
|
||||
class LabelAdmin(admin.ModelAdmin):
|
||||
search_fields = ('name',)
|
||||
list_display = ('name', 'color')
|
||||
list_editable = ('color',)
|
||||
|
||||
|
||||
@admin.register(Question)
|
||||
class QuestionAdmin(admin.ModelAdmin):
|
||||
autocomplete_fields = ('medias', 'links', 'labels',)
|
||||
list_display = ('name', 'list_labels', 'list_level', 'author')
|
||||
search_fields = ('name', 'question', 'awnser', 'description', 'label__name', 'level__value', 'level__name',)
|
||||
|
||||
def list_labels(self, instance):
|
||||
return mark_safe(', '.join([color_label(l, value=l.name) for l in instance.labels.all()]))
|
||||
|
||||
def list_level(self, instance):
|
||||
return mark_safe(color_label(instance.level, value=str(instance.level)))
|
||||
|
||||
list_level.short_description = 'Level'
|
||||
list_labels.short_description = 'Labels'
|
||||
|
||||
"""
|
||||
fieldsets = [
|
||||
('Basic', {'fields': [('name', 'author',)]}),
|
||||
('Question', {'fields': ('question', 'awnser',), }),
|
||||
('Meta', {'fields': ('level', 'labels', 'description'), }),
|
||||
('Media and Links', {'fields': ('medias', 'links'), },
|
||||
)
|
||||
]
|
||||
"""
|
||||
|
||||
|
||||
@admin.register(MediaFile)
|
||||
class MediaFileAdmin(admin.ModelAdmin):
|
||||
search_fields = ('name', 'file__name')
|
||||
list_display = ('name', 'file')
|
||||
|
||||
|
||||
@admin.register(Link)
|
||||
class LinkAdmin(admin.ModelAdmin):
|
||||
search_fields = ('url',)
|
||||
|
||||
|
||||
@admin.register(QuestionVersion)
|
||||
class QuestionVersionAdmin(admin.ModelAdmin):
|
||||
def has_add_permission(self, request):
|
||||
"""If a group right is not set :)
|
||||
Allways be able to create a version
|
||||
"""
|
||||
return True
|
||||
|
||||
def has_change_permission(self, request, obj=None):
|
||||
"""Versions are immutable """
|
||||
return False
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
"""Versions are immutable """
|
||||
return False
|
||||
Reference in New Issue
Block a user