From 81cbf39df7d634eb173d6b081c72d90dd4bd313b Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Tue, 9 Jun 2015 22:00:21 +0200 Subject: [PATCH] Konverze bodu na decimal(8,1) --- seminar/migrations/0022_decimal_body.py | 30 +++++++++++++++++++++++++ seminar/models.py | 10 +++++---- seminar/tests.py | 4 ++-- 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 seminar/migrations/0022_decimal_body.py diff --git a/seminar/migrations/0022_decimal_body.py b/seminar/migrations/0022_decimal_body.py new file mode 100644 index 00000000..0fb0c427 --- /dev/null +++ b/seminar/migrations/0022_decimal_body.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals +import importlib + +from django.db import models, migrations + +migration_0022 = importlib.import_module('seminar.migrations.0002_add_body_views') +print dir(migration_0022) + +class Migration(migrations.Migration): + + dependencies = [ + ('seminar', '0021_cislo_verejna_vysledkovka'), + ] + operations = [ + migrations.RunSQL(migration_0022.DROP_VIEWS), + migrations.AlterField( + model_name='problem', + name='body', + field=models.DecimalField(null=True, verbose_name='maximum bod\u016f', max_digits=8, decimal_places=1, blank=True), + preserve_default=True, + ), + migrations.AlterField( + model_name='reseni', + name='body', + field=models.DecimalField(null=True, verbose_name='body', max_digits=8, decimal_places=1, blank=True), + preserve_default=True, + ), + migrations.RunSQL(migration_0022.CREATE_VIEWS), + ] diff --git a/seminar/models.py b/seminar/models.py index 56b25627..6f43d225 100644 --- a/seminar/models.py +++ b/seminar/models.py @@ -364,7 +364,7 @@ class Problem(SeminarModelBase): cislo_reseni = models.ForeignKey(Cislo, verbose_name=u'číslo řešení', blank=True, null=True, related_name=u'resene_problemy', help_text=u'Číslo s řešením úlohy, jen pro úlohy') - body = models.IntegerField(u'maximum bodů', blank=True, null=True) + body = models.DecimalField(max_digits=8, decimal_places=1, verbose_name=u'maximum bodů', blank=True, null=True) timestamp = models.DateTimeField(u'vytvořeno', default=timezone.now, blank=True, editable=False) @@ -414,7 +414,7 @@ class Reseni(SeminarModelBase): resitel = models.ForeignKey(Resitel, verbose_name=u'řešitel', related_name='reseni') - body = models.IntegerField(u'body', blank=True, null=True) + body = models.DecimalField(max_digits=8, decimal_places=1, verbose_name=u'body', blank=True, null=True) cislo_body = models.ForeignKey(Cislo, verbose_name=u'číslo pro body', related_name='bodovana_reseni', blank=True, null=True) @@ -562,7 +562,8 @@ class VysledkyBase(SeminarModelBase): resitel = models.ForeignKey(Resitel, verbose_name=u'řešitel', db_column='resitel_id', on_delete=models.DO_NOTHING) - body = models.IntegerField(u'body za číslo', db_column='body') + body = models.DecimalField(max_digits=8, decimal_places=1, db_column='body', + verbose_name=u'body za číslo') def __str__(self): return force_unicode(u"%s: %sb (%s)" % (self.resitel.plne_jmeno(), self.body, str(self.cislo))) @@ -589,7 +590,8 @@ class VysledkyKCislu(VysledkyBase): abstract = False managed = False - body_celkem = models.IntegerField(u'body celkem do čísla', db_column='body_celkem') + body_celkem = models.DecimalField(max_digits=8, decimal_places=1, db_column='body_celkem', + verbose_name=u'body celkem do čísla') def __str__(self): # NOTE: DB HOG (ale nepouzivany) diff --git a/seminar/tests.py b/seminar/tests.py index 2a22d721..f8246294 100644 --- a/seminar/tests.py +++ b/seminar/tests.py @@ -29,7 +29,7 @@ class SeminarBasicTests(TestCase): def test_render_cislo_e2e(self): cs = Cislo.objects.all() for c in cs[:4]: - url = reverse('seminar_cislo', args=(c.id,)) + url = c.verejne_url() r = self.client.get(url) assert r.status_code == 200 assert len(r.content) >= 100 @@ -38,7 +38,7 @@ class SeminarBasicTests(TestCase): def test_render_problem_e2e(self): ps = Problem.objects.all() for p in ps[:4]: - url = reverse('seminar_problem', args=(p.id,)) + url = p.verejne_url() r = self.client.get(url) assert r.status_code == 200 assert len(r.content) >= 100