On corrige la catégorie par défaut

This commit is contained in:
Jean-Marie Favreau 2024-09-14 23:40:41 +02:00
parent 6f92cdf3c1
commit a1c5819de0
2 changed files with 30 additions and 4 deletions

View File

@ -0,0 +1,24 @@
# Generated by Django 4.2.9 on 2024-09-14 13:18
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('agenda_culturel', '0077_category_position_alter_event_category_and_more'),
]
operations = [
migrations.AlterField(
model_name='event',
name='category',
field=models.ForeignKey(default=1, help_text='Category of the event', null=True, on_delete=django.db.models.deletion.SET_DEFAULT, to='agenda_culturel.category', verbose_name='Category'),
),
migrations.AlterField(
model_name='recurrentimport',
name='defaultCategory',
field=models.ForeignKey(default=1, help_text='Category of each imported event', on_delete=django.db.models.deletion.SET_DEFAULT, to='agenda_culturel.category', verbose_name='Category'),
),
]

View File

@ -137,6 +137,12 @@ class Category(models.Model):
def get_default_category():
try:
# try to get an existing category
default = Category.objects.get(name=Category.default_name)
return default
except:
# if it does not exist, return it
default, created = Category.objects.get_or_create(
name=Category.default_name,
alt_name=Category.default_alt_name,
@ -144,10 +150,6 @@ class Category(models.Model):
color=Category.default_color,
)
return default
except:
return None
def get_default_category_id():
cat = Category.get_default_category()
if cat: