Opened 19 years ago

Closed 19 years ago

#441 closed defect (invalid)

A non-required DateTimeField produces an error on save

Reported by: jay@… Owned by: Adrian Holovaty
Component: contrib.admin Version:
Severity: normal Keywords: DateTImeField required replace
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a simple model that contains 2 DateTimeField's. One required and one not. Upon save, if the non-required field does not have a value, django throws an error.

Here is the model.

from django.core import meta

class Event(meta.Model):

start_date = meta.DateTimeField('Start Date')
end_date = meta.DateTimeField('End Date', blank=True)

class META:

admin = meta.Admin()

def repr(self):

return self.start_da

and the error

There's been an error:

Traceback (most recent call last):

File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py",

line 64, in get_response

response = callback(request, param_dict)

File "/usr/lib/python2.4/site-packages/django/views/admin/main.py",

line 777, in add_stage

new_object = manipulator.save(new_data)

File "/usr/lib/python2.4/site-packages/django/utils/functional.py",

line 3, in _curried

return args[0](*(args[1:]+moreargs), dict(kwargs.items() +

morekwargs.items()))

File "/usr/lib/python2.4/site-packages/django/core/meta/init.py",

line 1463, in manipulator_save

new_object.save()

File "/usr/lib/python2.4/site-packages/django/utils/functional.py",

line 3, in _curried

return args[0](*(args[1:]+moreargs), dict(kwargs.items() +

morekwargs.items()))

File "/usr/lib/python2.4/site-packages/django/core/meta/init.py",

line 793, in method_save

db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.column),

True)) for f in opts.fields if not isinstance(f, AutoField)]

File "/usr/lib/python2.4/site-packages/django/core/meta/fields.py",

line 333, in get_db_prep_save

value = value.replace(microsecond=0)

TypeError: replace() takes no keyword arguments

Change History (1)

comment:1 by Adrian Holovaty, 19 years ago

Resolution: invalid
Status: newclosed

You need null=True on the field that can be blank.

Note: See TracTickets for help on using tickets.
Back to Top