mirror of
https://github.com/ae-utbm/sith.git
synced 2026-09-01 10:09:17 +00:00
add created_at column to Subscription
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
# Generated by Django 5.2.17 on 2026-09-01 08:44
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import django.utils.timezone
|
||||
from django.db import migrations, models
|
||||
from django.db.migrations.state import StateApps
|
||||
from django.db.models import F, Min, Value
|
||||
from django.db.models.functions import Least
|
||||
from django.utils.timezone import now
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import subscription.models
|
||||
|
||||
|
||||
def make_default_creation_date(apps: StateApps, schema_editor):
|
||||
Subscription = apps.get_model("subscription", "Subscription")
|
||||
Subscription.objects.update(
|
||||
created_at=Least(
|
||||
F("subscription_start"), Value(now()), output_field=models.DateTimeField()
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("subscription", "0016_alter_subscription_subscription_type")]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="subscription",
|
||||
name="created_at",
|
||||
field=models.DateTimeField(
|
||||
auto_now_add=True,
|
||||
default=django.utils.timezone.now,
|
||||
help_text=(
|
||||
"When this subscription was created. "
|
||||
"This date may differ from the start of the subscription."
|
||||
),
|
||||
verbose_name="created_at",
|
||||
),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.RunPython(
|
||||
make_default_creation_date,
|
||||
reverse_code=migrations.RunPython.noop,
|
||||
elidable=True,
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user