Opened 18 years ago
Closed 17 years ago
#3146 closed defect (fixed)
'str' object has no attribute 'strftime' Error when the foreign key is a date
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | normal | Keywords: | date foreign key |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When a model use a date as foreign key, the admin interface crash when creating or editing an object.
For exemple, the following model crash when creating Event in the admin interface:
class Day(models.Model): date = models.DateField(primary_key=True, db_column='Date') class Admin: pass class Event(models.Model): id_event = models.AutoField(primary_key=True, db_column='idEvent') date = models.ForeignKey(JourneeElectorale, db_column='Date') class Admin: pass
Complete error is :
Exception Type: AttributeError
Exception Value: 'str' object has no attribute 'strftime'
Exception Location: /usr/lib/python2.4/site-packages/django/db/models/fields/init.py in get_db_prep_save, line 467
Attachments (2)
Change History (11)
comment:1 by , 18 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 by , 17 years ago
The Traceback with the last SVN version and Python 2.5:
Traceback (most recent call last):
File "/usr/local/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
- response = callback(request, *callback_args, callback_kwargs)
File "/usr/local/lib/python2.5/site-packages/django/contrib/admin/views/decorators.py" in _checklogin
- return view_func(request, *args, kwargs)
File "/usr/local/lib/python2.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
- response = view_func(request, *args, kwargs)
File "/usr/local/lib/python2.5/site-packages/django/contrib/admin/views/main.py" in add_stage
- new_object = manipulator.save(new_data)
File "/usr/local/lib/python2.5/site-packages/django/db/models/manipulators.py" in save
- new_object.save()
File "/usr/local/lib/python2.5/site-packages/django/db/models/base.py" in save
- db_values = [f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, True)) for f in self._meta.fields if not isinstance(f, AutoField)]
File "/usr/local/lib/python2.5/site-packages/django/db/models/fields/related.py" in get_db_prep_save
- return self.rel.get_related_field().get_db_prep_save(value)
File "/usr/local/lib/python2.5/site-packages/django/db/models/fields/init.py" in get_db_prep_save
- value = value.strftime('%Y-%m-%d')
AttributeError at /admin/foreigndate/event/add/
'unicode' object has no attribute 'strftime'
by , 17 years ago
Attachment: | unicode_strftime_fix.diff added |
---|
comment:4 by , 17 years ago
Has patch: | set |
---|---|
Needs tests: | set |
I could reproduce it. I added a patch, not intensively tested but working for me. I think this problem arose due to unicode fixes.
comment:5 by , 17 years ago
Needs tests: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
comment:6 by , 17 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
What directory is the file being patched in? There are many files called __init__.py
in the tree. Plesae regenerate the patch from the top of the source tree.
comment:7 by , 17 years ago
Patch needs improvement: | set |
---|
by , 17 years ago
Attachment: | unicode_strftime_fix.2.diff added |
---|
comment:8 by , 17 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
comment:9 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I could reproduce it.