ordering → base_altitude
This commit is contained in:
parent
b7e909645c
commit
5cf0157f50
2 changed files with 36 additions and 5 deletions
29
src/c3nav/mapdata/migrations/0031_auto_20170805_1647.py
Normal file
29
src/c3nav/mapdata/migrations/0031_auto_20170805_1647.py
Normal file
|
@ -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'),
|
||||
),
|
||||
]
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue