membershipworks: Convert EventExt.details_timestamp
to GeneratedField
was waiting on Django 5.0.5 to fix https://code.djangoproject.com/ticket/35350
This commit is contained in:
parent
281c882a82
commit
1310e72e3f
@ -160,7 +160,7 @@ class EventAdmin(DjangoObjectActions, admin.ModelAdmin):
|
|||||||
else:
|
else:
|
||||||
fields.append(field.name)
|
fields.append(field.name)
|
||||||
fields.insert(fields.index("end") + 1, "duration")
|
fields.insert(fields.index("end") + 1, "duration")
|
||||||
fields.append("_details_timestamp")
|
fields.append("details_timestamp")
|
||||||
return fields
|
return fields
|
||||||
|
|
||||||
@admin.display(ordering="title")
|
@admin.display(ordering="title")
|
||||||
@ -178,10 +178,6 @@ class EventAdmin(DjangoObjectActions, admin.ModelAdmin):
|
|||||||
obj.url,
|
obj.url,
|
||||||
)
|
)
|
||||||
|
|
||||||
@admin.display(description="Last details fetch")
|
|
||||||
def _details_timestamp(self, obj):
|
|
||||||
return naturaltime(obj.details_timestamp)
|
|
||||||
|
|
||||||
@takes_instance_or_queryset
|
@takes_instance_or_queryset
|
||||||
def fetch_details(self, request, queryset):
|
def fetch_details(self, request, queryset):
|
||||||
scrape_event_details(queryset)
|
scrape_event_details(queryset)
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
# Generated by Django 5.0.6 on 2024-05-08 16:44
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("membershipworks", "0017_eventext_registrations_alter_eventinvoice_pdf"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="eventext",
|
||||||
|
name="details_timestamp",
|
||||||
|
field=models.GeneratedField(
|
||||||
|
db_persist=False,
|
||||||
|
expression=models.Func(
|
||||||
|
models.Func(models.F("details___ts"), function="FROM_UNIXTIME"),
|
||||||
|
template="CONVERT_TZ(%(expressions)s, @@session.time_zone, 'UTC')",
|
||||||
|
),
|
||||||
|
output_field=models.DateTimeField(),
|
||||||
|
verbose_name="Last details fetch",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
@ -520,14 +520,6 @@ class EventExtManager(models.Manager):
|
|||||||
ExpressionWrapper(F("duration"), models.IntegerField()) * F("count"),
|
ExpressionWrapper(F("duration"), models.IntegerField()) * F("count"),
|
||||||
models.DurationField(),
|
models.DurationField(),
|
||||||
),
|
),
|
||||||
# TODO: this could be a GeneratedField, but that
|
|
||||||
# currently breaks saving when the primary key is
|
|
||||||
# provided (Django 5.0.1)
|
|
||||||
details_timestamp=Func(
|
|
||||||
Func(F("details___ts"), function="FROM_UNIXTIME"),
|
|
||||||
template="CONVERT_TZ(%(expressions)s, @@session.time_zone, 'UTC')",
|
|
||||||
output_field=models.DateTimeField(),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -550,6 +542,16 @@ class EventExt(Event):
|
|||||||
max_digits=13, decimal_places=4, default=0
|
max_digits=13, decimal_places=4, default=0
|
||||||
)
|
)
|
||||||
details = models.JSONField(null=True, blank=True)
|
details = models.JSONField(null=True, blank=True)
|
||||||
|
details_timestamp = models.GeneratedField(
|
||||||
|
expression=Func(
|
||||||
|
Func(F("details___ts"), function="FROM_UNIXTIME"),
|
||||||
|
template="CONVERT_TZ(%(expressions)s, @@session.time_zone, 'UTC')",
|
||||||
|
),
|
||||||
|
output_field=models.DateTimeField(),
|
||||||
|
db_persist=False,
|
||||||
|
verbose_name="Last details fetch",
|
||||||
|
)
|
||||||
|
|
||||||
registrations = models.JSONField(null=True, blank=True)
|
registrations = models.JSONField(null=True, blank=True)
|
||||||
|
|
||||||
def get_absolute_url(self) -> str:
|
def get_absolute_url(self) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user