can't add via admin, get django template error

89 views
Skip to first unread message

JeffH

unread,
Dec 8, 2010, 11:49:02 AM12/8/10
to Django users
So I'm working along, everything's humming fine. Then I try to add a
record via the admin, and get the following:

TemplateSyntaxError at /admin/expert/expertresponse/add/
Caught AttributeError while rendering: 'unicode' object has no
attribute 'date'

[snip]

Template error

In template c:\python26\lib\site-packages\django\contrib\admin
\templates\admin\includes\fieldset.html, error at line 12
Caught AttributeError while rendering: 'unicode' object has no
attribute 'date'
2 {% if fieldset.name %}<h2>{{ fieldset.name }}</h2>{% endif %}
3 {% if fieldset.description %}<div
class="description">{{ fieldset.description|safe }}</div>{% endif %}
4 {% for line in fieldset %}
5 <div class="form-row{% if line.errors %} errors{% endif %} {% for
field in line %}{{ field.field.name }} {% endfor %} ">
6 {{ line.errors }}
7 {% for field in line %}
8 <div{% if not line.fields|length_is:"1" %} class="field-box"{%
endif %}>
9 {% if field.is_checkbox %}
10 {{ field.field }}{{ field.label_tag }}
11 {% else %}
12 {{ field.label_tag }}{{ field.field }}

I can add records via a ModelForm without problem, it just doesn't
work in the admin.

Wayne Smith

unread,
Dec 8, 2010, 2:20:14 PM12/8/10
to django...@googlegroups.com
As you probably surmised from the error, the admin is expecting a field attribute of type date on your  model object (line?).  Anyway, what is getting passed is an Unicode object, which obviously does not have the attribute (field) it is looking for.

I would guess that the problem lies somewhere in your admin file (admin.py).  What are the contents of it?
 

JeffH

unread,
Dec 9, 2010, 2:52:21 PM12/9/10
to Django users
I had defined a custom admin class for that model. I commented it out
and went with the default admin class, and got the same error trying
to create a new record. So didn't think it was the admin.

Then I looked at the date fields on that model. Turned out that
specifying a default date as a string was the problem:
publish_date = models.DateTimeField(default='2039-12-31') # don't!

Even though it works with a standard ModelForm form, ie gets displayed
in the UI properly, is accepted as a valid date by the Form
validation, and gets inserted into the db properly.

I think that the admin should accept such a (properly formed) date
string. Or else the model shouldn't validate.

On Dec 8, 2:20 pm, Wayne Smith <wayne.tuxro...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages