Code

Opened 9 years ago

Closed 9 years ago

#441 closed defect (invalid)

A non-required DateTimeField produces an error on save

Reported by: jay@… Owned by: adrian
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: UI/UX:

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

Attachments (0)

Change History (1)

comment:1 Changed 9 years ago by adrian

  • Resolution set to invalid
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.