mirror of
https://github.com/quantum5/peeringdb-mirror.git
synced 2025-04-24 10:11:58 -04:00
Store aware times for better interaction with other Django apps
This commit is contained in:
parent
a6e057cf60
commit
944b96eea7
19
peeringdb_api/backend.py
Normal file
19
peeringdb_api/backend.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
import zoneinfo
|
||||
|
||||
from django.db.models import DateTimeField, Model
|
||||
from django.utils import timezone
|
||||
from django_peeringdb import __version__ # noqa
|
||||
from django_peeringdb.client_adaptor.backend import Backend as OldBackend
|
||||
|
||||
utc = zoneinfo.ZoneInfo('UTC')
|
||||
|
||||
|
||||
class Backend(OldBackend):
|
||||
def clean(self, obj: Model):
|
||||
for field in obj._meta.get_fields():
|
||||
if isinstance(field, DateTimeField):
|
||||
value = getattr(obj, field.name)
|
||||
if timezone.is_naive(value):
|
||||
setattr(obj, field.name, timezone.make_aware(value, utc))
|
||||
|
||||
super().clean(obj)
|
|
@ -1,4 +1,4 @@
|
|||
from django_peeringdb.client_adaptor import backend
|
||||
from peeringdb_api import backend
|
||||
|
||||
|
||||
def load_backend(**kwargs):
|
||||
|
|
Loading…
Reference in a new issue