Browse Source

Pridano pocitani reseni problemu a resitelu

remotes/origin/feincms
Tomas Gavenciak 10 years ago
parent
commit
a1505485a1
  1. 15
      seminar/admin.py

15
seminar/admin.py

@ -4,6 +4,7 @@ from django import forms
import reversion
from solo.admin import SingletonModelAdmin
from ckeditor.widgets import CKEditorWidget
from django.db.models import Count
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici
import autocomplete_light
@ -101,14 +102,18 @@ class ResitelAdmin(reversion.VersionAdmin):
(u'Osobní údaje', {'fields': ['pohlavi_muz', 'datum_narozeni', 'email', 'telefon']}),
(u'Adresa', {'fields': ['ulice', 'mesto', 'psc', 'stat']}),
]
list_display = ['jmeno', 'prijmeni', 'user', 'pohlavi_muz', 'skola', 'rok_maturity']
list_display = ['jmeno', 'prijmeni', 'user', 'pohlavi_muz', 'skola', 'rok_maturity', 'pocet_reseni']
list_filter = ['pohlavi_muz', 'rok_maturity', 'zasilat']
search_fields = ['jmeno', 'prijmeni', 'ulice', 'user', 'mesto', 'email']
inlines = [ReseniKResiteliInline]
def get_queryset(self, request):
qs = super(ResitelAdmin, self).get_queryset(request)
return qs.select_related('skola', 'user')
return qs.select_related('skola', 'user').annotate(pocet_reseni=Count('reseni'))
def pocet_reseni(self, obj):
return obj.pocet_reseni
admin.site.register(Resitel, ResitelAdmin)
@ -217,7 +222,7 @@ class ProblemAdmin(reversion.VersionAdmin):
(None, {'fields': ['text_problemu_org']}),
]
readonly_fields = ['timestamp']
list_display = ['nazev', 'typ', 'kod', 'stav', 'autor', 'opravovatel', 'verejne', 'cislo_zadani']
list_display = ['nazev', 'typ', 'kod', 'stav', 'autor', 'opravovatel', 'verejne', 'cislo_zadani', 'pocet_reseni']
list_select_related = True
list_filter = ['typ', 'stav', 'timestamp']
search_fields = ['nazev', 'kod', 'text_problemu_org', 'text_problemu']
@ -226,8 +231,10 @@ class ProblemAdmin(reversion.VersionAdmin):
def get_queryset(self, request):
qs = super(ProblemAdmin, self).get_queryset(request)
return qs.select_related('autor', 'opravovatel', 'cislo_zadani', 'cislo_reseni')
return qs.select_related('autor', 'opravovatel', 'cislo_zadani', 'cislo_reseni').annotate(pocet_reseni=Count('reseni'))
def pocet_reseni(self, obj):
return obj.pocet_reseni
admin.site.register(Problem, ProblemAdmin)

Loading…
Cancel
Save