feat: Add slug to species
This commit is contained in:
18
src/fellchensammlung/migrations/0065_species_slug.py
Normal file
18
src/fellchensammlung/migrations/0065_species_slug.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.1 on 2025-09-06 13:02
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('fellchensammlung', '0064_alter_animal_name_alter_animal_photos_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='species',
|
||||
name='slug',
|
||||
field=models.SlugField(null=True, unique=True, verbose_name='Slug'),
|
||||
),
|
||||
]
|
20
src/fellchensammlung/migrations/0066_add_slug_to_species.py
Normal file
20
src/fellchensammlung/migrations/0066_add_slug_to_species.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 5.2.1 on 2025-09-06 13:05
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def migrate_slug(apps, schema_editor):
|
||||
Species = apps.get_model("fellchensammlung", "Species")
|
||||
for species in Species.objects.all():
|
||||
species.slug = f"species-{species.id}"
|
||||
species.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('fellchensammlung', '0065_species_slug'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(migrate_slug),
|
||||
]
|
18
src/fellchensammlung/migrations/0067_alter_species_slug.py
Normal file
18
src/fellchensammlung/migrations/0067_alter_species_slug.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.1 on 2025-09-06 13:12
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('fellchensammlung', '0066_add_slug_to_species'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='species',
|
||||
name='slug',
|
||||
field=models.SlugField(unique=True, verbose_name='Slug'),
|
||||
),
|
||||
]
|
@@ -129,6 +129,7 @@ class Species(models.Model):
|
||||
"""Model representing a species of animal."""
|
||||
name = models.CharField(max_length=200, help_text=_('Name der Tierart'),
|
||||
verbose_name=_('Name'))
|
||||
slug = models.SlugField(unique=True, verbose_name=_('Slug'))
|
||||
updated_at = models.DateTimeField(auto_now=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
|
Reference in New Issue
Block a user