Přidání pdf do modelu Cislo
This commit is contained in:
parent
3265dff111
commit
2f2a3e3b50
3 changed files with 29 additions and 1 deletions
|
@ -195,7 +195,7 @@ admin.site.register(Skola, SkolaAdmin)
|
||||||
|
|
||||||
class CisloAdmin(reversion.VersionAdmin):
|
class CisloAdmin(reversion.VersionAdmin):
|
||||||
fieldsets = [
|
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']}),
|
(u'Data', {'fields': ['datum_vydani', 'datum_deadline']}),
|
||||||
]
|
]
|
||||||
list_display = ['kod', 'rocnik', 'cislo', 'datum_vydani', 'datum_deadline', 'verejne', 'verejna_vysledkovka']
|
list_display = ['kod', 'rocnik', 'cislo', 'datum_vydani', 'datum_deadline', 'verejne', 'verejna_vysledkovka']
|
||||||
|
|
21
seminar/migrations/0031_cislo_pdf.py
Normal file
21
seminar/migrations/0031_cislo_pdf.py
Normal file
|
@ -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,
|
||||||
|
),
|
||||||
|
]
|
|
@ -305,6 +305,9 @@ class Rocnik(SeminarModelBase):
|
||||||
return c
|
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)
|
@reversion.register(ignore_duplicate_revisions=True)
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
|
@ -338,6 +341,9 @@ class Cislo(SeminarModelBase):
|
||||||
poznamka = models.TextField(u'neveřejná poznámka', blank=True,
|
poznamka = models.TextField(u'neveřejná poznámka', blank=True,
|
||||||
help_text=u'Neveřejná poznámka k číslu (plain text)')
|
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):
|
def kod(self):
|
||||||
return u'%s.%s' % (self.rocnik.rocnik, self.cislo)
|
return u'%s.%s' % (self.rocnik.rocnik, self.cislo)
|
||||||
kod.short_description = u'Kód čísla'
|
kod.short_description = u'Kód čísla'
|
||||||
|
@ -370,6 +376,7 @@ class Cislo(SeminarModelBase):
|
||||||
return None
|
return None
|
||||||
return cs[i]
|
return cs[i]
|
||||||
|
|
||||||
|
|
||||||
@reversion.register(ignore_duplicate_revisions=True)
|
@reversion.register(ignore_duplicate_revisions=True)
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Problem(SeminarModelBase):
|
class Problem(SeminarModelBase):
|
||||||
|
|
Loading…
Reference in a new issue