Browse Source

Admin: odkazy na čísla zadání/řešení z problémů

remotes/origin/test
Matěj Kocián 8 years ago
parent
commit
c7a792257f
  1. 30
      seminar/admin.py

30
seminar/admin.py

@ -8,6 +8,8 @@ from solo.admin import SingletonModelAdmin
from ckeditor.widgets import CKEditorWidget from ckeditor.widgets import CKEditorWidget
from django.db.models import Count from django.db.models import Count
from django.db import models from django.db import models
from django.utils.safestring import mark_safe
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User from django.contrib.auth.models import User
@ -478,11 +480,37 @@ create_modeladmin(ProblemNavrhAdmin, Problem, 'ProblemNavrh', verbose_name=u'Pro
class ProblemZadanyAdmin(ProblemAdmin): class ProblemZadanyAdmin(ProblemAdmin):
list_display = ['nazev', 'typ', 'autor', 'opravovatel', 'kod', 'verejne'] list_display = [
'nazev',
'typ',
'cislo_zadani_link',
'cislo_reseni_link',
'autor',
'opravovatel',
'kod',
'verejne'
]
list_filter = [ list_filter = [
'typ', 'zamereni', 'cislo_zadani__cislo', 'cislo_zadani__rocnik' 'typ', 'zamereni', 'cislo_zadani__cislo', 'cislo_zadani__rocnik'
] ]
def cislo_zadani_link(self, obj):
return mark_safe('<a href="{}">{}</a>'.format(
reverse("admin:seminar_cislo_change", args=(obj.cislo_zadani.pk,)),
obj.cislo_zadani
))
cislo_zadani_link.short_description = u'Číslo zadání'
# TODO pokud se budou odkazy v adminu více používat, možná by se hodilo je
# nějak zjednodušit, např. tímto?
# https://github.com/gitaarik/django-admin-relation-links
def cislo_reseni_link(self, obj):
return mark_safe('<a href="{}">{}</a>'.format(
reverse("admin:seminar_cislo_change", args=(obj.cislo_reseni.pk,)),
obj.cislo_reseni
))
cislo_reseni_link.short_description = u'Číslo řešení'
def get_inline_instances(self, request, obj=None): def get_inline_instances(self, request, obj=None):
if obj and obj.typ == Problem.TYP_ULOHA: if obj and obj.typ == Problem.TYP_ULOHA:
inlines = [ReseniKProblemuInline, PohadkaKProblemuInline] inlines = [ReseniKProblemuInline, PohadkaKProblemuInline]

Loading…
Cancel
Save