-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Savage-Aim/timezone-fix
Timezone fix
- Loading branch information
Showing
3 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from datetime import timezone | ||
from django.core.management.base import BaseCommand | ||
from api.models import Character, Notification | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Fix all the Timestamps in the DB that are missing tzinfo' | ||
|
||
def handle(self, *args, **options): | ||
for obj in Character.objects.all(): | ||
if obj.created.tzinfo is None: | ||
self.stdout.write(f'Updating created stamp for {obj}') | ||
obj.created = obj.created.astimezone(timezone.utc) | ||
obj.save() | ||
|
||
for obj in Notification.objects.all(): | ||
if obj.timestamp.tzinfo is None: | ||
self.stdout.write(f'Updating timestamp for {obj}') | ||
obj.timestamp = obj.timestamp.astimezone(timezone.utc) | ||
obj.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters