agendas: add an index on Event (#77590)

This commit is contained in:
Lauréline Guérin 2023-05-24 20:48:19 +02:00 committed by Lauréline Guérin
parent 11559acd35
commit 31f4e5c059
2 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,21 @@
import django.db.models.expressions
import django.db.models.functions.datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('agendas', '0152_auto_20230331_0834'),
]
operations = [
migrations.AddIndex(
model_name='event',
index=models.Index(
django.db.models.functions.datetime.ExtractWeekDay('start_datetime'),
django.db.models.expressions.F('start_datetime'),
condition=models.Q(('cancelled', False)),
name='start_datetime_dow_index',
),
),
]

View File

@ -1536,6 +1536,14 @@ class Event(models.Model):
class Meta:
ordering = ['agenda', 'start_datetime', 'duration', 'label']
unique_together = ('agenda', 'slug')
indexes = [
models.Index(
ExtractWeekDay('start_datetime'),
'start_datetime',
name='start_datetime_dow_index',
condition=models.Q(cancelled=False),
)
]
def __str__(self):
if self.label: