I'm going around in circles on this on and need some help. I continue to get a naive timezone
warning. Not sure what I am doing wrong! Arg.
Here is the warning:
/django/db/models/fields/__init__.py:1222: RuntimeWarning: DateTimeField Video.modified received a naive datetime (2014-10-07 00:00:00) while time zone support is active.
RuntimeWarning)
Here is the model code (redacted somewhat):
from django.db import models
from django.utils import timezone
class ItemBase(models.Model):
created = models.DateTimeField(editable=False)
modified = models.DateTimeField(editable=False)
class Meta:
abstract = True
def save(self, *args, **kwargs):
"""Updates timestamps on save"""
if not self.id:
self.created = timezone.now()
self.modified = timezone.now()
return super(ItemBase, self).save(*args, **kwargs)
class Video(ItemBase):
pass
And the relevant (I think) part of my settings file:
TIME_ZONE = 'UTC'
USE_TZ = True
Is this a sqlite issue (am still testing things)? Or am I missing something fundamental here? I've read up on it here and here and, of course, at the docs here. But I am stumped. Thanks.
edit: added test that throws the error
Am getting the error when I run my tests ... I left the redacted stuff in there but you should get the idea:
from django.test import TestCase
from django.contrib.auth import get_user_model
from video.models import Video, VideoAccount
class VideoTestCase(TestCase):
def setUp(self):
user = get_user_model().objects.create_user(
username='jacob', email='jacob@test.com', password='top_secret')
self.video_account = VideoAccount.objects.create(
account_type=1, account_id=12345, display_name="Test Account" )
self.pk1 = Video.objects.create(video_type=1, video_id="Q7X3fyId2U0",
video_account=self.video_account, owner=user)
def test_video_creation(self):
"""Creates a video object"""
self.assertEqual(self.pk1.video_id, "Q7X3fyId2U0")
self.assertEqual(self.pk1.video_link, "https://www.youtube.com/watch?v=Q7X3fyId2U0")