add Level.short_label
This commit is contained in:
parent
fbc9efd2a0
commit
48fb0e4555
4 changed files with 45 additions and 2 deletions
38
src/c3nav/mapdata/migrations/0041_level_short_label.py
Normal file
38
src/c3nav/mapdata/migrations/0041_level_short_label.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.6 on 2017-10-25 10:19
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def add_short_label(apps, schema_editor):
|
||||
models = ('AltitudeArea', 'AltitudeMarker', 'Area', 'Building', 'Column', 'Door', 'GraphNode', 'Hole',
|
||||
'LineObstacle', 'Obstacle', 'POI', 'Space', 'Stair')
|
||||
Level = apps.get_model('mapdata', 'level')
|
||||
for level in Level.objects.all():
|
||||
level.short_label = level.slug or str(level.pk)
|
||||
level.save()
|
||||
|
||||
def remove_short_label(apps, schema_editor):
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mapdata', '0040_access_permissions'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='level',
|
||||
name='short_label',
|
||||
field=models.CharField(null=True, max_length=20, unique=True, verbose_name='short label'),
|
||||
),
|
||||
migrations.RunPython(add_short_label, remove_short_label),
|
||||
migrations.AlterField(
|
||||
model_name='level',
|
||||
name='short_label',
|
||||
field=models.CharField(max_length=20, unique=True, verbose_name='short label'),
|
||||
),
|
||||
]
|
|
@ -30,6 +30,7 @@ class Level(SpecificLocation, models.Model):
|
|||
default_height = models.DecimalField(_('default space height'), max_digits=6, decimal_places=2, default=3.0)
|
||||
on_top_of = models.ForeignKey('mapdata.Level', null=True, on_delete=models.CASCADE,
|
||||
related_name='levels_on_top', verbose_name=_('on top of'))
|
||||
short_label = models.CharField(max_length=20, verbose_name=_('short label'), unique=True)
|
||||
|
||||
render_data = models.BinaryField(null=True)
|
||||
|
||||
|
@ -81,6 +82,7 @@ class Level(SpecificLocation, models.Model):
|
|||
|
||||
def _serialize(self, level=True, **kwargs):
|
||||
result = super()._serialize(**kwargs)
|
||||
result['short_label'] = self.short_label
|
||||
result['on_top_of'] = self.on_top_of_id
|
||||
result['base_altitude'] = float(str(self.base_altitude))
|
||||
result['default_height'] = float(str(self.default_height))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue