When I try to set my datetime field to today's date in two of my models via the admin I get the error "couldn't be interpreted in time zone America/Los_Angeles; it may be ambiguous or it may not exist". This only happens in these two models. If I try to set datetime to today's date in other models (most of which are not shown), there are no problems.
Here are the relevant models from model.py:
from django.db import models
# DateTimeField has no problem with today's date in this model
class Subject(models.Model):
title = models.CharField(max_length=200, unique=True)
date_created = models.DateTimeField('date created')
times_viewed = models.IntegerField()
# Both DateTimeFields give an error in this model
class Discussion(models.Model):
subject = models.ForeignKey(Subject)
title = models.CharField(max_length=200)
version = models.CharField(max_length=200)
created = models.DateTimeField('date created')
updated = models.DateTimeField('date updated')
creator = models.CharField(max_length=200)
# DateTimeField gives an error in this model too
class DiscussionPost(models.Model):
discussion = models.ForeignKey(Discussion)
poster = models.CharField(max_length=200)
text = models.TextField()
posted = models.DateTimeField('date posted')
Here is the relevant part of admin.py:
from django.contrib import admin
from my_app.models import Subject, Discussion, DiscussionPost # and other irrelevant models
class DiscussionPostInline(admin.StackedInline):
model = DiscussionPost
extra = 1
class DiscussionAdmin(admin.ModelAdmin):
fieldsets = [
('Title', {'fields': ['title']}),
('Creator', {'fields': ['creator']}),
('Date Created', {'fields': ['created']}),
('Date Updated', {'fields': ['updated']}),
]
inlines = [DiscussionPostInline]
list_display = ('title', 'creator', 'created', 'updated')
admin.site.register(Discussion, DiscussionAdmin)
DiscussionInline(admin.StackedInline):
model = Discussion
extra = 1
SubjectAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['title']}),
('Times Viewed', {'fields': ['times_viewed'], 'classes': ['collapse']}),
('Date Created', {'fields': ['date_created'], 'classes': ['collapse']}),
]
inlines = [DiscussionInline]
list_display = ('title', 'times_viewed', 'date_created')
list_filter = ['date_created']
search_fields = ['title']
date_hierarchy = 'date_created'
admin.site.register(Subject, SubjectAdmin)
If I manually change to a different day from the admin, I do not get the error. It is just when I use today's date (both manually and using now() ). Anybody know why this may be happening?
This admin structure is based on the second answer to this Django Admin nested inline.
UPDATE I changed the datetime within the admin and now it works. I didn't change anything in the models or admin so I am stumped as to why it wasn't working earlier this morning.