From 2f2a3e3b5070202688eaef1cd1269c352349fa12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Koci=C3=A1n?= Date: Sat, 12 Sep 2015 12:35:30 +0200 Subject: [PATCH] =?UTF-8?q?P=C5=99id=C3=A1n=C3=AD=20pdf=20do=20modelu=20Ci?= =?UTF-8?q?slo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/admin.py | 2 +- seminar/migrations/0031_cislo_pdf.py | 21 +++++++++++++++++++++ seminar/models.py | 7 +++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 seminar/migrations/0031_cislo_pdf.py diff --git a/seminar/admin.py b/seminar/admin.py index eeb415ac..f7f63434 100644 --- a/seminar/admin.py +++ b/seminar/admin.py @@ -195,7 +195,7 @@ admin.site.register(Skola, SkolaAdmin) class CisloAdmin(reversion.VersionAdmin): fieldsets = [ - (None, {'fields': ['cislo', 'rocnik', 'verejne_db', 'verejna_vysledkovka', 'poznamka']}), + (None, {'fields': ['cislo', 'rocnik', 'verejne_db', 'verejna_vysledkovka', 'poznamka', 'pdf']}), (u'Data', {'fields': ['datum_vydani', 'datum_deadline']}), ] list_display = ['kod', 'rocnik', 'cislo', 'datum_vydani', 'datum_deadline', 'verejne', 'verejna_vysledkovka'] diff --git a/seminar/migrations/0031_cislo_pdf.py b/seminar/migrations/0031_cislo_pdf.py new file mode 100644 index 00000000..c51570bf --- /dev/null +++ b/seminar/migrations/0031_cislo_pdf.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +import seminar.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0030_add_vysledky'), + ] + + operations = [ + migrations.AddField( + model_name='cislo', + name='pdf', + field=models.FileField(help_text='Pdf \u010d\xedsla, kter\xe9 si mohou \u0159e\u0161itel\xe9 st\xe1hnout', upload_to=seminar.models.cislo_pdf_filename, null=True, verbose_name='pdf'), + preserve_default=True, + ), + ] diff --git a/seminar/models.py b/seminar/models.py index c5a80b27..3e9f19cd 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -305,6 +305,9 @@ class Rocnik(SeminarModelBase): return c +def cislo_pdf_filename(self, filename): + rocnik = str(self.rocnik.rocnik) + return os.path.join('cislo', 'pdf', rocnik, '{}-{}.pdf'.format(rocnik, self.cislo)) @reversion.register(ignore_duplicate_revisions=True) @python_2_unicode_compatible @@ -338,6 +341,9 @@ class Cislo(SeminarModelBase): poznamka = models.TextField(u'neveřejná poznámka', blank=True, help_text=u'Neveřejná poznámka k číslu (plain text)') + pdf = models.FileField(u'pdf', upload_to=cislo_pdf_filename, null=True, + help_text=u'Pdf čísla, které si mohou řešitelé stáhnout') + def kod(self): return u'%s.%s' % (self.rocnik.rocnik, self.cislo) kod.short_description = u'Kód čísla' @@ -370,6 +376,7 @@ class Cislo(SeminarModelBase): return None return cs[i] + @reversion.register(ignore_duplicate_revisions=True) @python_2_unicode_compatible class Problem(SeminarModelBase):