From fa0c4e0fa9ea3ade64deeff053a584fb4d119052 Mon Sep 17 00:00:00 2001 From: "Bc. Petr Pecha" Date: Tue, 23 Jun 2015 10:50:58 +0200 Subject: [PATCH 1/5] Novinky | vytvoreni modelu --- seminar/models.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/seminar/models.py b/seminar/models.py index 6f43d225..6c2c99cb 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -618,3 +618,22 @@ class Nastaveni(SingletonModel): def verejne(self): return False + + +@python_2_unicode_compatible +class Novinky(models.Model): + datum = models.DateField(auto_now_add=True) + text = models.TextField('Text novinky', blank=True, null=True) + obrazek = models.ImageField('Obrázek', upload_to='image_novinky/%Y/%m/%d/', + null=True, blank=True) + autor = models.ForeignKey(settings.AUTH_USER_MODEL, + verbose_name='Autor novinky') + zverejneno = models.BooleanField('Zveřejněno', default="False") + + def __str__(self): + return '[' + self.datum + '] ' + self.text[0:20] + + class Meta: + verbose_name = 'Novinka' + verbose_name_plural = 'Novinky' + From 836905b3de723a0c585963fbb476887651d6a177 Mon Sep 17 00:00:00 2001 From: "Bc. Petr Pecha" Date: Tue, 23 Jun 2015 11:30:08 +0200 Subject: [PATCH 2/5] Novinky | vytvoreni modelu --- seminar/migrations/0023_add_novinky.py | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 seminar/migrations/0023_add_novinky.py diff --git a/seminar/migrations/0023_add_novinky.py b/seminar/migrations/0023_add_novinky.py new file mode 100644 index 00000000..3babdc2d --- /dev/null +++ b/seminar/migrations/0023_add_novinky.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +from django.conf import settings + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('seminar', '0022_decimal_body'), + ] + + operations = [ + migrations.CreateModel( + name='Novinky', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('datum', models.DateField(auto_now_add=True)), + ('text', models.TextField(null=True, verbose_name=b'Text novinky', blank=True)), + ('obrazek', models.ImageField(upload_to=b'image_novinky/%Y/%m/%d/', null=True, verbose_name=b'Obr\xc3\xa1zek', blank=True)), + ('zverejneno', models.BooleanField(default=b'False', verbose_name=b'Zve\xc5\x99ejn\xc4\x9bno')), + ('autor', models.ForeignKey(verbose_name=b'Autor novinky', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'verbose_name': 'Novinka', + 'verbose_name_plural': 'Novinky', + }, + bases=(models.Model,), + ), + ] From 42df6f9265527e429a859a63536b05b4d2f11c84 Mon Sep 17 00:00:00 2001 From: "Bc. Petr Pecha" Date: Tue, 23 Jun 2015 11:32:16 +0200 Subject: [PATCH 3/5] Novinky | admin --- seminar/admin.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/seminar/admin.py b/seminar/admin.py index d8fdd2aa..39ff2f05 100644 --- a/seminar/admin.py +++ b/seminar/admin.py @@ -8,7 +8,7 @@ from ckeditor.widgets import CKEditorWidget from django.db.models import Count from django.db import models -from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici +from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni, Soustredeni_Ucastnici, Novinky import autocomplete_light @@ -317,3 +317,9 @@ class SoustredeniAdmin(reversion.VersionAdmin): admin.site.register(Soustredeni, SoustredeniAdmin) +### Novinky + +class NovinkyAdmin(admin.ModelAdmin): + pass + +admin.site.register(Novinky, NovinkyAdmin) From 60a93713b3095b6b42fb04790304834960449e80 Mon Sep 17 00:00:00 2001 From: "Bc. Petr Pecha" Date: Tue, 23 Jun 2015 11:36:42 +0200 Subject: [PATCH 4/5] Novinky | oprava chyby se zobrazovanym nazvem --- seminar/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seminar/models.py b/seminar/models.py index 6c2c99cb..04890ef9 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -631,7 +631,7 @@ class Novinky(models.Model): zverejneno = models.BooleanField('Zveřejněno', default="False") def __str__(self): - return '[' + self.datum + '] ' + self.text[0:20] + return '[' + str(self.datum) + '] ' + self.text[0:50] class Meta: verbose_name = 'Novinka' From 3ed0e6d6d03d9fc8e9a7ae809acba7db5d4b746c Mon Sep 17 00:00:00 2001 From: "Bc. Petr Pecha" Date: Tue, 23 Jun 2015 11:46:45 +0200 Subject: [PATCH 5/5] Novinky | CKEditor --- seminar/admin.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/seminar/admin.py b/seminar/admin.py index 39ff2f05..dcb7797d 100644 --- a/seminar/admin.py +++ b/seminar/admin.py @@ -319,7 +319,15 @@ admin.site.register(Soustredeni, SoustredeniAdmin) ### Novinky +class NovinkyAdminForm(forms.ModelForm): + text = forms.CharField(widget=CKEditorWidget(), required=False, + **field_labels(Novinky, 'text')) + class Meta: + model = Novinky + exclude = [] + class NovinkyAdmin(admin.ModelAdmin): - pass + form = NovinkyAdminForm + admin.site.register(Novinky, NovinkyAdmin)