Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#557 closed defect (fixed)

date_hierarchy doesn't work with DateField

Reported by: kyrrigle@… Owned by: Adrian Holovaty
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: no UI/UX: no

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:

Change History (6)

comment:1 by Adrian Holovaty, 19 years ago

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

comment:2 by kyrrigle@…, 19 years ago

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 by Adrian Holovaty, 19 years ago

Resolution: worksforme
Status: newclosed

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 by Esaj <jason at jasondavies.com>, 19 years ago

Resolution: worksforme
Status: closedreopened

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 by mildly@…, 19 years ago

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 by Malcolm Tredinnick <malcolm@…>, 19 years ago

Resolution: fixed
Status: reopenedclosed

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

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