Skip to content

Commit fea54f8

Browse files
committed
Add migrations for Items external price and periodic tasks
1 parent ffe59da commit fea54f8

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by Django 5.1.7 on 2025-08-01 11:09
2+
3+
from decimal import Decimal
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("items", "0001_initial"),
11+
]
12+
13+
operations = [
14+
migrations.AddField(
15+
model_name="item",
16+
name="external_price",
17+
field=models.DecimalField(
18+
decimal_places=2,
19+
default=Decimal("0.00"),
20+
help_text="Price from external system (simulated)",
21+
max_digits=10,
22+
),
23+
),
24+
]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Generated by Django 5.1.7 on 2025-08-01 12:18
2+
3+
import json
4+
5+
from django.db import migrations
6+
7+
8+
def create_hourly_sync_task(apps, schema_editor):
9+
"""
10+
Create a periodic task to sync external prices hourly.
11+
This task will update the external_price field of all Item instances.
12+
"""
13+
IntervalSchedule = apps.get_model("django_celery_beat", "IntervalSchedule")
14+
PeriodicTask = apps.get_model("django_celery_beat", "PeriodicTask")
15+
16+
schedule, _ = IntervalSchedule.objects.get_or_create(every=1, period="hours")
17+
18+
PeriodicTask.objects.get_or_create(
19+
name="Hourly external price sync",
20+
defaults={
21+
"interval": schedule,
22+
"task": "items.tasks.hourly_external_price_sync",
23+
"kwargs": json.dumps({}),
24+
},
25+
)
26+
27+
28+
class Migration(migrations.Migration):
29+
30+
dependencies = [
31+
("items", "0002_item_external_price"),
32+
("django_celery_beat", "0001_initial"),
33+
]
34+
35+
operations = [
36+
migrations.RunPython(create_hourly_sync_task),
37+
]

0 commit comments

Comments
 (0)