remove compiled_room and compiled_area, create location group categories
This commit is contained in:
parent
5d336d218a
commit
ca237d7884
2 changed files with 44 additions and 11 deletions
|
@ -0,0 +1,41 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.2 on 2017-07-11 15:51
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def convert_compiled_room_area_to_location_group_category(apps, schema_editor):
|
||||
LocationGroupCategory = apps.get_model('mapdata', 'LocationGroupCategory')
|
||||
LocationGroup = apps.get_model('mapdata', 'LocationGroup')
|
||||
|
||||
compiled_room = LocationGroupCategory.objects.create(name='compiled_room', titles={
|
||||
'en': 'Compiled room',
|
||||
'de': 'Zusammengefügter Raum',
|
||||
}, single=True, allow_levels=False, allow_spaces=True, allow_areas=True, allow_pois=False, priority=1)
|
||||
LocationGroup.objects.filter(compiled_room=True).update(category=compiled_room)
|
||||
|
||||
compiled_area = LocationGroupCategory.objects.create(name='compiled_area', titles={
|
||||
'en': 'Compiled area',
|
||||
'de': 'Zusammengefügter Bereich',
|
||||
}, single=True, allow_levels=False, allow_spaces=True, allow_areas=True, allow_pois=False, priority=2)
|
||||
LocationGroup.objects.filter(compiled_area=True).update(category=compiled_area)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mapdata', '0023_auto_20170711_1741'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(convert_compiled_room_area_to_location_group_category),
|
||||
migrations.RemoveField(
|
||||
model_name='locationgroup',
|
||||
name='compiled_area',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='locationgroup',
|
||||
name='compiled_room',
|
||||
),
|
||||
]
|
|
@ -123,16 +123,10 @@ class Location(LocationSlug, TitledMixin, models.Model):
|
|||
# dont filter in the query here so prefetch_related works
|
||||
if instance is None:
|
||||
instance = self
|
||||
groups = [group for group in instance.groups.all() if group.color]
|
||||
if not groups:
|
||||
return None
|
||||
for group in groups:
|
||||
if group.compiled_area:
|
||||
for group in instance.groups.all():
|
||||
if group.color:
|
||||
return group.color
|
||||
for group in groups:
|
||||
if group.compiled_room:
|
||||
return group.color
|
||||
return groups[0].color
|
||||
return None
|
||||
|
||||
|
||||
class SpecificLocation(Location, models.Model):
|
||||
|
@ -177,8 +171,6 @@ class LocationGroupCategory(TitledMixin, models.Model):
|
|||
class LocationGroup(Location, models.Model):
|
||||
category = models.ForeignKey(LocationGroupCategory, related_name='groups', on_delete=models.PROTECT,
|
||||
verbose_name=_('Category'))
|
||||
compiled_room = models.BooleanField(default=False, verbose_name=_('is a compiled room'))
|
||||
compiled_area = models.BooleanField(default=False, verbose_name=_('is a compiled area'))
|
||||
priority = models.IntegerField(default=0, db_index=True)
|
||||
|
||||
class Meta:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue