Code

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#557 closed defect (fixed)

date_hierarchy doesn't work with DateField

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

Description

Trying to use a DateField in the meta.Admin(date_hierarch="dateFld") yields the following exception when going to the admin list page:

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/db/typecasts.py", line 23, in typecast_timestamp
    d, t = s.split()

A simple patch to make typecast_timestamp work with just dates is:

===================================================================
--- django/core/db/typecasts.py (revision 687)
+++ django/core/db/typecasts.py (working copy)
@@ -20,7 +20,12 @@
     # "2005-07-29 15:48:00.590358-05"
     # "2005-07-29 09:56:00-05"
     if not s: return None
-    d, t = s.split()
+    flds = s.split()
+    d = flds[0]
+    if len(flds) == 1:
+        t = "00:00:01"  # or noon?
+    else:
+        t = flds[1]
     # Extract timezone information, if it exists. Currently we just throw
     # it away, but in the future we may make use of it.
     if '-' in t:

Attachments (0)

Change History (6)

comment:1 Changed 9 years ago by adrian

That's strange -- it should work. Can you paste the offending model?

comment:2 Changed 9 years ago by kyrrigle@…

  • Cc kyrrigle@… added

Just change the polls example pub_date to be a meta.DateField, sqlreset and add a poll.

Full stack trace:

There's been an error:

Traceback (most recent call last):

  File "D:\django-trunk\django\core\handlers\base.py", line 64, in get_response
    response = callback(request, **param_dict)

  File "D:\django-trunk\django\views\admin\main.py", line 327, in change_list
    for year in getattr(lookup_mod, 'get_%s_list' % field_name)('year', **lookup_params):

  File "D:\django-trunk\django\utils\functional.py", line 3, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))

  File "D:\django-trunk\django\core\meta\__init__.py", line 1387, in function_get_date_list
    return [typecast_timestamp(str(row[0])) for row in cursor.fetchall()]

  File "D:\django-trunk\django\core\db\typecasts.py", line 23, in typecast_timestamp
    d, t = s.split()

ValueError: unpack list of wrong size

comment:3 Changed 9 years ago by adrian

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

I did that, and it worked fine for me. I also verified it on a completely separate model that I'm developing, and it worked fine, too. I suspect you forgot to do sqlreset, or have some other bug in your model.

comment:4 Changed 8 years ago by Esaj <jason at jasondavies.com>

  • Resolution worksforme deleted
  • Status changed from closed to reopened

I'm getting this problem too. It seems that s is equal to the string 'None' when this happens. I'm using SQLite.

comment:5 Changed 8 years ago by mildly@…

This is exactly the same problem (and solution) I ran into when using date-based generic views with SQLite 'Date' fields.

It's because a Date field only returns the date, whereas the typecasts function expects the date and time.

I am currently working on updating the SQLite3 wrapper to use SQLite's internal date handling functions.

comment:6 Changed 8 years ago by Malcolm Tredinnick <malcolm@…>

  • Resolution set to fixed
  • Status changed from reopened to closed

This was fixed in [1971] as part of ticket #1062.

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.