From c7a792257f23252b9822e67c97fd0e999afdc8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Fri, 21 Apr 2017 22:43:08 +0200 Subject: [PATCH] =?UTF-8?q?Admin:=20odkazy=20na=20=C4=8D=C3=ADsla=20zad?= =?UTF-8?q?=C3=A1n=C3=AD/=C5=99e=C5=A1en=C3=AD=20z=20probl=C3=A9m=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/admin.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/seminar/admin.py b/seminar/admin.py index 9ce11a93..cdb9f3fc 100644 --- a/seminar/admin.py +++ b/seminar/admin.py @@ -8,6 +8,8 @@ from solo.admin import SingletonModelAdmin from ckeditor.widgets import CKEditorWidget from django.db.models import Count 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 @@ -478,11 +480,37 @@ create_modeladmin(ProblemNavrhAdmin, Problem, 'ProblemNavrh', verbose_name=u'Pro 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 = [ 'typ', 'zamereni', 'cislo_zadani__cislo', 'cislo_zadani__rocnik' ] + def cislo_zadani_link(self, obj): + return mark_safe('{}'.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('{}'.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): if obj and obj.typ == Problem.TYP_ULOHA: inlines = [ReseniKProblemuInline, PohadkaKProblemuInline]