From 5cf0157f50c9779670f04ba9e7ba38bbf7701dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Kl=C3=BCnder?= Date: Sat, 5 Aug 2017 16:49:10 +0200 Subject: [PATCH] =?UTF-8?q?ordering=20=E2=86=92=20base=5Faltitude?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0031_auto_20170805_1647.py | 29 +++++++++++++++++++ src/c3nav/mapdata/models/level.py | 12 ++++---- 2 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 src/c3nav/mapdata/migrations/0031_auto_20170805_1647.py diff --git a/src/c3nav/mapdata/migrations/0031_auto_20170805_1647.py b/src/c3nav/mapdata/migrations/0031_auto_20170805_1647.py new file mode 100644 index 00000000..5d9fac73 --- /dev/null +++ b/src/c3nav/mapdata/migrations/0031_auto_20170805_1647.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.2 on 2017-08-05 14:47 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('mapdata', '0030_altitudes'), + ] + + operations = [ + migrations.AlterModelOptions( + name='level', + options={'ordering': ['base_altitude'], 'verbose_name': 'Level', 'verbose_name_plural': 'Levels'}, + ), + migrations.RenameField( + model_name='level', + old_name='ordering', + new_name='base_altitude', + ), + migrations.AlterField( + model_name='level', + name='base_altitude', + field=models.DecimalField(decimal_places=2, max_digits=6, unique=True, verbose_name='base altitude'), + ), + ] diff --git a/src/c3nav/mapdata/models/level.py b/src/c3nav/mapdata/models/level.py index 457c556f..a7a1d32c 100644 --- a/src/c3nav/mapdata/models/level.py +++ b/src/c3nav/mapdata/models/level.py @@ -15,7 +15,7 @@ class Level(SpecificLocation, models.Model): """ A map level """ - ordering = models.DecimalField(_('ordering'), null=False, unique=True, max_digits=6, decimal_places=2) + base_altitude = models.DecimalField(_('base altitude'), null=False, unique=True, max_digits=6, decimal_places=2) on_top_of = models.ForeignKey('mapdata.Level', null=True, on_delete=models.CASCADE, related_name='levels_on_top', verbose_name=_('on top of')) @@ -23,7 +23,7 @@ class Level(SpecificLocation, models.Model): verbose_name = _('Level') verbose_name_plural = _('Levels') default_related_name = 'levels' - ordering = ['ordering'] + ordering = ['base_altitude'] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -33,14 +33,16 @@ class Level(SpecificLocation, models.Model): raise TypeError if level_model is None: level_model = Level - return level_model.objects.filter(ordering__lt=self.ordering, on_top_of__isnull=True).order_by('-ordering') + return level_model.objects.filter(base_altitude__lt=self.base_altitude, + on_top_of__isnull=True).order_by('-base_altitude') def higher(self, level_model=None): if self.on_top_of_id is not None: raise TypeError if level_model is None: level_model = Level - return level_model.objects.filter(ordering__gt=self.ordering, on_top_of__isnull=True).order_by('ordering') + return level_model.objects.filter(base_altitude__gt=self.base_altitude, + on_top_of__isnull=True).order_by('base_altitude') @property def sublevels(self): @@ -62,7 +64,7 @@ class Level(SpecificLocation, models.Model): def _serialize(self, level=True, **kwargs): result = super()._serialize(**kwargs) - result['ordering'] = float(str(self.ordering)) + result['base_altitude'] = float(str(self.base_altitude)) return result def _render_space_ground(self, svg, space):