From 1166c8864812baa8ad71f890b3a2e5464af44c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Thu, 24 Sep 2015 00:43:05 +0200 Subject: [PATCH] =?UTF-8?q?Admin:=20zm=C4=9Bna=20zp=C5=AFsobu=20zobrazov?= =?UTF-8?q?=C3=A1n=C3=AD=20cel=C3=A9ho=20jm=C3=A9na?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nepadá, ale nepředvyplňuje se --- seminar/admin.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/seminar/admin.py b/seminar/admin.py index c0b0311b..c28e54b9 100644 --- a/seminar/admin.py +++ b/seminar/admin.py @@ -8,13 +8,18 @@ from solo.admin import SingletonModelAdmin from ckeditor.widgets import CKEditorWidget from django.db.models import Count from django.db import models + from django.contrib.auth.models import User from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici, Novinky, Organizator import autocomplete_light -uzivatele = [(user, u"{} ({})".format(user.get_full_name(), user)) for user in User.objects.filter(is_staff=True)] +uzivatele = [(user, u"{} ()".format(1)) for user in User.objects.filter(is_staff=True)] +print(uzivatele) +class UserModelChoiceField(forms.ModelChoiceField): + def label_from_instance(self, obj): + return u"{} ({})".format(obj.get_full_name(), obj.username) def predvypln_prihlaseneho(*pole): u"""Dekorátor pro Adminy. Předvyplní do *polí přihlášeného uživatele. @@ -297,8 +302,8 @@ class ProblemAdminForm(forms.ModelForm): text_reseni = forms.CharField(widget=CKEditorWidget(), required=False, **field_labels(Problem, 'text_reseni')) text_org = forms.CharField(widget=CKEditorWidget(), required=False, **field_labels(Problem, 'text_org')) zamereni = TaggitField(widget=TaggitWidget('TagAutocomplete'), required=False) - autor = forms.ChoiceField(choices=uzivatele) - opravovatel = forms.ChoiceField(choices=uzivatele) + autor = UserModelChoiceField(User.objects.filter(is_staff=True)) + opravovatel = UserModelChoiceField(User.objects.filter(is_staff=True)) class Meta: model = Problem exclude = [] @@ -379,7 +384,8 @@ admin.site.register(Soustredeni, SoustredeniAdmin) class NovinkyAdminForm(forms.ModelForm): text = forms.CharField(widget=CKEditorWidget(), required=False, **field_labels(Novinky, 'text')) - autor = forms.ChoiceField(choices=uzivatele) + autor = UserModelChoiceField(User.objects.filter(is_staff=True)) + class Meta: model = Novinky exclude = []