On utilise l'ID plutôt qu'un UUID, parce que sinon c'est galère
This commit is contained in:
parent
5962375713
commit
00df29ef4d
@ -1,36 +0,0 @@
|
|||||||
# Generated by Django 4.2.1 on 2023-10-14 09:53
|
|
||||||
|
|
||||||
import django.contrib.postgres.fields
|
|
||||||
from django.db import migrations, models
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
initial = True
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='Event',
|
|
||||||
fields=[
|
|
||||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
||||||
('slug', models.SlugField(editable=False, unique=True)),
|
|
||||||
('created_date', models.DateTimeField(auto_now_add=True)),
|
|
||||||
('modified_date', models.DateTimeField(auto_now=True)),
|
|
||||||
('title', models.CharField(help_text='Short title', max_length=512, verbose_name='Title')),
|
|
||||||
('status', models.CharField(choices=[('published', 'Published'), ('trash', 'Trash'), ('draft', 'draft')], default='published', max_length=20, verbose_name='Status')),
|
|
||||||
('start_day', models.DateField(help_text='Day of the event', verbose_name='Day of the event')),
|
|
||||||
('start_time', models.TimeField(help_text='Starting time', verbose_name='Starting time')),
|
|
||||||
('end_day', models.DateField(help_text='End day of the event, only required if different from the start day.', verbose_name='End day of the event')),
|
|
||||||
('end_time', models.TimeField(help_text='Final time', verbose_name='Final time')),
|
|
||||||
('location', models.CharField(help_text='Address of the event', max_length=512, verbose_name='Location')),
|
|
||||||
('description', models.TextField(blank=True, help_text='General description of the event', null=True, verbose_name='Description')),
|
|
||||||
('image', models.URLField(help_text='URL of the illustration image', verbose_name='Illustration')),
|
|
||||||
('image_alt', models.CharField(help_text='Alternative text used by screen readers for the image', max_length=512, verbose_name='Illustration description')),
|
|
||||||
('reference_urls', django.contrib.postgres.fields.ArrayField(base_field=models.URLField(), help_text='List of all the urls where this event can be found.', size=None, verbose_name='URLs')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
@ -1,44 +0,0 @@
|
|||||||
# Generated by Django 4.2.1 on 2023-10-14 10:04
|
|
||||||
|
|
||||||
import django.contrib.postgres.fields
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('agenda_culturel', '0001_initial'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='event',
|
|
||||||
name='end_day',
|
|
||||||
field=models.DateField(blank=True, help_text='End day of the event, only required if different from the start day.', null=True, verbose_name='End day of the event'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='event',
|
|
||||||
name='end_time',
|
|
||||||
field=models.TimeField(blank=True, help_text='Final time', null=True, verbose_name='Final time'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='event',
|
|
||||||
name='image',
|
|
||||||
field=models.URLField(blank=True, help_text='URL of the illustration image', null=True, verbose_name='Illustration'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='event',
|
|
||||||
name='image_alt',
|
|
||||||
field=models.CharField(blank=True, help_text='Alternative text used by screen readers for the image', max_length=512, null=True, verbose_name='Illustration description'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='event',
|
|
||||||
name='reference_urls',
|
|
||||||
field=django.contrib.postgres.fields.ArrayField(base_field=models.URLField(), blank=True, help_text='List of all the urls where this event can be found.', null=True, size=None, verbose_name='URLs'),
|
|
||||||
),
|
|
||||||
migrations.AlterField(
|
|
||||||
model_name='event',
|
|
||||||
name='start_time',
|
|
||||||
field=models.TimeField(blank=True, help_text='Starting time', null=True, verbose_name='Starting time'),
|
|
||||||
),
|
|
||||||
]
|
|
@ -3,7 +3,6 @@ from django.contrib.postgres.fields import ArrayField
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.template.defaultfilters import slugify # new
|
from django.template.defaultfilters import slugify # new
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
import uuid
|
|
||||||
|
|
||||||
from django.template.defaultfilters import date as _date
|
from django.template.defaultfilters import date as _date
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -16,8 +15,6 @@ class Event(models.Model):
|
|||||||
TRASH = "trash", _("Trash")
|
TRASH = "trash", _("Trash")
|
||||||
DRAFT = "draft", _("Draft")
|
DRAFT = "draft", _("Draft")
|
||||||
|
|
||||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
||||||
slug = models.SlugField(null=False, unique=True, editable=False)
|
|
||||||
created_date = models.DateTimeField(auto_now_add=True)
|
created_date = models.DateTimeField(auto_now_add=True)
|
||||||
modified_date = models.DateTimeField(auto_now=True)
|
modified_date = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
@ -41,12 +38,7 @@ class Event(models.Model):
|
|||||||
reference_urls = ArrayField(models.URLField(max_length=200), verbose_name=_('URLs'), help_text=_("List of all the urls where this event can be found."), blank=True, null=True)
|
reference_urls = ArrayField(models.URLField(max_length=200), verbose_name=_('URLs'), help_text=_("List of all the urls where this event can be found."), blank=True, null=True)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse("view_event", kwargs={"slug": self.slug})
|
return reverse("view_event", kwargs={"pk": self.pk, "extra": self.title})
|
||||||
|
|
||||||
def save(self, *args, **kwargs): # new
|
|
||||||
if not self.slug:
|
|
||||||
self.slug = slugify(str(self.id) + "-" + self.title)
|
|
||||||
return super().save(*args, **kwargs)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return _date(self.start_day) + ": " + self.title
|
return _date(self.start_day) + ": " + self.title
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<h1>Événements</h1>
|
<h1>Événements</h1>
|
||||||
<ul>
|
<ul>
|
||||||
{% for event in object_list %}
|
{% for event in object_list %}
|
||||||
<li><a href="{{ BASE_URL }}{{ event.get_absolute_url }}">{{ event.start_day|date }} - {{ event.title }}</a></li>
|
<li><a href="{{ BASE_URL }}{{ event.get_absolute_url }}">{{ event.start_day|date }} : {{ event.title }}</a></li>
|
||||||
{% empty %}
|
{% empty %}
|
||||||
<li>Il n'y a pas d'événement.</li>
|
<li>Il n'y a pas d'événement.</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -10,7 +10,7 @@ from .views import *
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", EventListView.as_view(), name="home"),
|
path("", EventListView.as_view(), name="home"),
|
||||||
re_path(r'^(?P<mode>' + '|'.join([dm.value for dm in DisplayModes]) + ')/$', view_interval, name='view_interval'),
|
re_path(r'^(?P<mode>' + '|'.join([dm.value for dm in DisplayModes]) + ')/$', view_interval, name='view_interval'),
|
||||||
path("event/<slug:slug>", EventDetailView.as_view(), name="view_event"),
|
path("event/<pk>-<extra>", EventDetailView.as_view(), name="view_event"),
|
||||||
path("admin/", admin.site.urls),
|
path("admin/", admin.site.urls),
|
||||||
path("test_app/", include("test_app.urls")),
|
path("test_app/", include("test_app.urls")),
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user