first commit
This commit is contained in:
commit
367533c02b
171 files changed
+101175
No files matched your search
@@ -0,0 +1,29 @@
|
||||
from datetime import datetime, time
|
||||
|
||||
from django.db import migrations
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
def backfill_timestamps(apps, schema_editor):
|
||||
IotPanel = apps.get_model("operations", "IotPanel")
|
||||
for row in IotPanel.objects.filter(timestamp__isnull=True):
|
||||
row.timestamp = timezone.make_aware(
|
||||
datetime.combine(row.date, time(0, 0)), timezone.get_current_timezone()
|
||||
)
|
||||
row.save(update_fields=["timestamp"])
|
||||
|
||||
|
||||
def unset_timestamps(apps, schema_editor):
|
||||
IotPanel = apps.get_model("operations", "IotPanel")
|
||||
IotPanel.objects.update(timestamp=None)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("operations", "0006_iotpanel_timestamp"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(backfill_timestamps, unset_timestamps),
|
||||
]
|
||||
Reference in new issue
Block a user