diff --git a/project/geosource/migrations/0009_alter_source_slug.py b/project/geosource/migrations/0009_alter_source_slug.py new file mode 100644 index 00000000..28b30d7c --- /dev/null +++ b/project/geosource/migrations/0009_alter_source_slug.py @@ -0,0 +1,20 @@ +# Generated by Django 4.1.8 on 2023-04-11 14:47 + +import autoslug.fields +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("geosource", "0008_alter_field_sample"), + ] + + operations = [ + migrations.AlterField( + model_name="source", + name="slug", + field=autoslug.fields.AutoSlugField( + editable=False, populate_from="name", unique=True + ), + ), + ] diff --git a/project/geosource/models.py b/project/geosource/models.py index 78ab1276..9931e047 100644 --- a/project/geosource/models.py +++ b/project/geosource/models.py @@ -7,6 +7,7 @@ import fiona import psycopg2 import pyexcel +from autoslug import AutoSlugField from celery.result import AsyncResult from celery.utils.log import LoggingProxy from django.conf import settings @@ -65,7 +66,7 @@ def get_type_from_data(cls, data): class Source(PolymorphicModel, CeleryCallMethodsMixin): name = models.CharField(max_length=255, unique=True) credit = models.TextField(blank=True) - slug = models.SlugField(max_length=255, unique=True) + slug = AutoSlugField(unique=True, populate_from="name") description = models.TextField(blank=True) id_field = models.CharField(max_length=255, default="id") diff --git a/project/terra_layer/migrations/0010_alter_scene_slug.py b/project/terra_layer/migrations/0010_alter_scene_slug.py new file mode 100644 index 00000000..ea7b9af1 --- /dev/null +++ b/project/terra_layer/migrations/0010_alter_scene_slug.py @@ -0,0 +1,20 @@ +# Generated by Django 4.1.8 on 2023-04-11 14:47 + +import autoslug.fields +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("terra_layer", "0009_alter_scene_base_layers"), + ] + + operations = [ + migrations.AlterField( + model_name="scene", + name="slug", + field=autoslug.fields.AutoSlugField( + editable=False, populate_from="name", unique=True + ), + ), + ] diff --git a/project/terra_layer/models.py b/project/terra_layer/models.py index 7362bef9..d9b00827 100644 --- a/project/terra_layer/models.py +++ b/project/terra_layer/models.py @@ -29,7 +29,7 @@ class Scene(models.Model): """ name = models.CharField(max_length=255, unique=True) - slug = models.SlugField(max_length=255, unique=True) + slug = AutoSlugField(unique=True, populate_from="name") category = models.CharField(max_length=255, default="map") custom_icon = models.ImageField( max_length=255, upload_to=scene_icon_path, null=True, default=None @@ -129,9 +129,6 @@ def insert_in_tree(self, layer, parts, group_config=None): self.save() def save(self, *args, **kwargs): - if not self.slug: - self.slug = slugify(self.name) - super().save(*args, **kwargs) self.tree2models() # Generate LayerGroups according to the tree diff --git a/project/visu/migrations/0006_alter_extramenuitem_slug.py b/project/visu/migrations/0006_alter_extramenuitem_slug.py new file mode 100644 index 00000000..1e4789a7 --- /dev/null +++ b/project/visu/migrations/0006_alter_extramenuitem_slug.py @@ -0,0 +1,20 @@ +# Generated by Django 4.1.8 on 2023-04-11 14:47 + +import autoslug.fields +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("visu", "0005_alter_extramenuitem_options"), + ] + + operations = [ + migrations.AlterField( + model_name="extramenuitem", + name="slug", + field=autoslug.fields.AutoSlugField( + editable=False, populate_from="label", unique=True + ), + ), + ] diff --git a/project/visu/models.py b/project/visu/models.py index 48019a7b..49ca6709 100644 --- a/project/visu/models.py +++ b/project/visu/models.py @@ -1,3 +1,4 @@ +from autoslug import AutoSlugField from django.db import models from django.utils.text import slugify from django.utils.translation import gettext_lazy as _ @@ -17,18 +18,13 @@ class ExtraMenuItem(models.Model): """Extra menu items included in frontend.""" label = models.CharField(max_length=255, unique=True) - slug = models.SlugField(max_length=255, unique=True, blank=True) + slug = AutoSlugField(unique=True, populate_from="label") href = models.CharField(max_length=255) icon = models.ImageField(upload_to="extra_menu_items/") def __str__(self): return self.label - def save(self, *args, **kwargs): - if not self.pk and not self.slug: - self.slug = slugify(self.label) - return super().save(*args, **kwargs) - class Meta: verbose_name = _("Extra menu item") verbose_name_plural = _("Extra menu items")