#17836 closed Bug (needsinfo)
Can't assign values for models.DateTimeField(blank=True, null=True)
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.4-beta-1 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Using Django 1.4b1 with timezone aware datetime objects
It seems to be the case that I cannot assign a value to a model's field and persist it to the database. The field is defined as
asked_on = models.DateTimeField(blank=True, null=True)
and I've tried datetime.now and timezone.now()
What happens is this:
model.asked_on = datetime.now() (or timezone.now())
print model.asked_on # None is printed to the console
model.save() #sql logs show a null value being put into the update query.
Change History (7)
comment:1 by , 13 years ago
Summary: | Can't assign values for models.DateTimeField(blank=True, null=True) → i should have previewed how the code would look |
---|
comment:2 by , 13 years ago
Summary: | i should have previewed how the code would look → Can't assign values for models.DateTimeField(blank=True, null=True) |
---|
comment:3 by , 13 years ago
I can't reproduce this on Django 1.4 RC 1 using sqlite and pg. Please tell us which database you use and provide some code we can use to reproduce.
comment:4 by , 13 years ago
Using MySQL. I know that mysql doesn't support timezone aware datetimes but does it make sense for the model to not accept values?
class MyModel(models.Model): #various other fields answered_on = models.DateTimeField(blank=True, null=True) modelToChange = MyModel.objects.get(pk=PK) form = MyModelForm(request.POST) if form.is_valid(): value = form.cleaned_data['value'] modelToChange.answer = answer modelToChange.answrerd_on = timezone.now() # or using datetime.now(), same problem print modelToChange.answered_on # this prints None regardless of previous method modelToChange.save() # generates a answered_on = NULL in the sql
comment:5 by , 13 years ago
Is the answrerd_on
typo copied from your actual code? Because that would fully explain the behavior you are seeing.
comment:6 by , 13 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
Closing as needsinfo pending reproduction code sans typo that still displays the problem.
Sorry, I should have previewed i guess.
model.asked_on = datetime.now() (or timezone.now())
print model.asked_on # None is printed to the console
model.save() #sql logs show a null value being put into the update query.