Admin: úpravy galerií
* tlačítko uložit nahoře * náhled obrázku ve volbě titulní fotky * řazení galerií podle (rodiče, pořadí)
This commit is contained in:
parent
607a94ff8c
commit
7599522a13
3 changed files with 74 additions and 8 deletions
|
@ -3,6 +3,9 @@
|
||||||
from galerie.models import Obrazek, Galerie
|
from galerie.models import Obrazek, Galerie
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
|
from django import forms
|
||||||
|
from django.db import models
|
||||||
|
import autocomplete_light
|
||||||
|
|
||||||
# akction
|
# akction
|
||||||
|
|
||||||
|
@ -27,17 +30,25 @@ def prepnout_fotogalerii_do_org_rezimu(modeladmin, request, queryset):
|
||||||
'Přepnout do režimu úprav (zneveřejní galerii)'
|
'Přepnout do režimu úprav (zneveřejní galerii)'
|
||||||
|
|
||||||
class GalerieInline(admin.TabularInline):
|
class GalerieInline(admin.TabularInline):
|
||||||
model = Obrazek
|
model = Obrazek
|
||||||
|
fields = ['obrazek_velky', 'nazev', 'popis', 'obrazek_maly_tag']
|
||||||
|
readonly_fields = ['nazev', 'obrazek_maly_tag']
|
||||||
|
formfield_overrides = {
|
||||||
|
models.TextField: {'widget': forms.TextInput},
|
||||||
|
}
|
||||||
|
|
||||||
class ObrazekAdmin(admin.ModelAdmin):
|
class ObrazekAdmin(admin.ModelAdmin):
|
||||||
list_display = ('obrazek_velky', 'nazev', 'popis')
|
list_display = ('obrazek_velky', 'nazev', 'popis', 'obrazek_maly_tag')
|
||||||
|
|
||||||
class GalerieAdmin(admin.ModelAdmin):
|
class GalerieAdmin(admin.ModelAdmin):
|
||||||
model = Galerie
|
form = autocomplete_light.modelform_factory(Galerie, autocomplete_fields=['titulni_obrazek'], fields=['titulni_obrazek'])
|
||||||
fields = ('zobrazit', 'nazev', 'titulni_obrazek', 'popis', 'galerie_up', 'soustredeni', 'poradi')
|
model = Galerie
|
||||||
list_display = ('nazev', 'pk', 'datum_zmeny', 'zobrazit', 'soustredeni')
|
fields = ('zobrazit', 'nazev', 'titulni_obrazek', 'popis', 'galerie_up', 'soustredeni', 'poradi')
|
||||||
inlines = [GalerieInline]
|
list_display = ('nazev', 'pk', 'poradi', 'datum_zmeny', 'zobrazit', 'soustredeni')
|
||||||
actions = [zverejnit_fotogalerii, prepnout_fotogalerii_do_org_rezimu]
|
inlines = [GalerieInline]
|
||||||
|
actions = [zverejnit_fotogalerii, prepnout_fotogalerii_do_org_rezimu]
|
||||||
|
save_on_top = True
|
||||||
|
ordering = ['galerie_up__nazev', 'poradi']
|
||||||
|
|
||||||
admin.site.register(Obrazek, ObrazekAdmin)
|
admin.site.register(Obrazek, ObrazekAdmin)
|
||||||
admin.site.register(Galerie, GalerieAdmin)
|
admin.site.register(Galerie, GalerieAdmin)
|
||||||
|
|
49
galerie/autocomplete_light_registry.py
Normal file
49
galerie/autocomplete_light_registry.py
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import autocomplete_light
|
||||||
|
|
||||||
|
from models import Obrazek, Galerie
|
||||||
|
from views import cesta_od_korene
|
||||||
|
|
||||||
|
|
||||||
|
class ObrazekAutocomplete(autocomplete_light.AutocompleteModelBase):
|
||||||
|
|
||||||
|
model = Obrazek
|
||||||
|
search_fields = ['nazev', 'popis']
|
||||||
|
split_words = True
|
||||||
|
limit_choices = 15
|
||||||
|
attrs = {
|
||||||
|
# This will set the input placeholder attribute:
|
||||||
|
'placeholder': u'Obrázek',
|
||||||
|
# This will set the yourlabs.Autocomplete.minimumCharacters
|
||||||
|
# options, the naming conversion is handled by jQuery
|
||||||
|
'data-autocomplete-minimum-characters': 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
choice_html_format = '''
|
||||||
|
<span class="block" data-value="{}">
|
||||||
|
<span class="block">
|
||||||
|
{}
|
||||||
|
<span class="block">{}</span>
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
'''
|
||||||
|
|
||||||
|
def choice_label(self, obrazek):
|
||||||
|
cesta = "/".join(g.nazev for g in cesta_od_korene(obrazek.galerie))
|
||||||
|
popis = "{}<br>".format(obrazek.popis) if obrazek.popis else ""
|
||||||
|
return '{}<br>{}{}'.format(obrazek.nazev, popis, cesta)
|
||||||
|
|
||||||
|
def choice_html(self, obrazek):
|
||||||
|
"""Vrátí kus html i s obrázkem, které se pak ukazuje v nabídce"""
|
||||||
|
return self.choice_html_format.format(self.choice_value(obrazek),
|
||||||
|
obrazek.obrazek_maly_tag(), self.choice_label(obrazek))
|
||||||
|
|
||||||
|
widget_attrs={
|
||||||
|
'data-widget-maximum-values': 15,
|
||||||
|
'class': 'modern-style',
|
||||||
|
}
|
||||||
|
|
||||||
|
autocomplete_light.register(ObrazekAutocomplete)
|
|
@ -56,6 +56,12 @@ class Obrazek(models.Model):
|
||||||
verbose_name = 'Obrázek'
|
verbose_name = 'Obrázek'
|
||||||
verbose_name_plural = 'Obrázky'
|
verbose_name_plural = 'Obrázky'
|
||||||
ordering = ['nazev']
|
ordering = ['nazev']
|
||||||
|
|
||||||
|
def obrazek_maly_tag(self):
|
||||||
|
return u'<img src="{}">'.format(self.obrazek_maly.url)
|
||||||
|
obrazek_maly_tag.short_description = "Náhled"
|
||||||
|
obrazek_maly_tag.allow_tags = True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Galerie(models.Model):
|
class Galerie(models.Model):
|
||||||
|
|
Loading…
Reference in a new issue