Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Nov. 16, 2005 09:30:02

l.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

FileUploadField bug?


I'm testing generic view, and I had a FileField in my polls model, but
as I summited, I got a Exception:

TypeError at /polls/add/
string indices must be integers
Request Method: POST
Request URL:http://127.0.0.1:8000/polls/add/Exception Type: TypeError
Exception Value: string indices must be integers
Exception Location:

c:\python24\lib\site-packages\django-0.90-py2.4.egg\django\core\formfields.py
in isNonEmptyFile, line 499

the code line is: if not field_data:

And I print the field_data, I saw it is a string, but not a list. Is this a bug?

--
I like python!
My Blog:http://www.donews.net/limodouNewEdit Maillist:http://groups.google.com/group/NewEdit

Offline

#2 Nov. 16, 2005 12:51:40

l.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

FileUploadField bug?


2005/11/16, limodou <>:
> I'm testing generic view, and I had a FileField in my polls model, but
> as I summited, I got a Exception:
>
> TypeError at /polls/add/
> string indices must be integers
> Request Method: POST
> Request URL:http://127.0.0.1:8000/polls/add/> Exception Type: TypeError
> Exception Value: string indices must be integers
> Exception Location:
>
> c:\python24\lib\site-packages\django-0.90-py2.4.egg\django\core\formfields.py
> in isNonEmptyFile, line 499
>
> the code line is: if not field_data:
>
> And I print the field_data, I saw it is a string, but not a list. Is this a
> bug?
>

I want to know why no one answer my email?

--
I like python!
My Blog:http://www.donews.net/limodouNewEdit Maillist:http://groups.google.com/group/NewEdit

Offline

#3 Nov. 16, 2005 15:44:31

Adrian H.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

FileUploadField bug?


On 11/16/05, limodou <> wrote:
> I'm testing generic view, and I had a FileField in my polls model, but
> as I summited, I got a Exception:

Hi limidou,

We can't help you much in this case, unless you paste your URLconf and
models. Go ahead and show us that stuff, and we'll be able to help
you!

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org

Offline

#4 Nov. 17, 2005 00:22:36

l.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

FileUploadField bug?


2005/11/16, Adrian Holovaty <>:
>
> On 11/16/05, limodou <> wrote:
> > I'm testing generic view, and I had a FileField in my polls model, but
> > as I summited, I got a Exception:
>
> Hi limidou,
>
> We can't help you much in this case, unless you paste your URLconf and
> models. Go ahead and show us that stuff, and we'll be able to help
> you!
>
Thanks to Adrian first.

May be it's a bug, I'v made a patch to it, the ticket is #816. I
followed the tutorial, my model is:

#coding=utf-8
from django.core import meta
import datetime

# Create your models here.

class Poll(meta.Model):
question = meta.CharField(maxlength=200)
pub_date = meta.DateTimeField('date published')
attachment = meta.FileField(upload_to='upload')

def __repr__(self):
return self.question

def was_published_today(self):
return self.pub_date.date() == datetime.date.today()
was_published_today.short_description = 'Was published today'

class META:
admin = meta.Admin(
fields = (
(None, {'fields': ('question',)}),
('Test', {'fields': ('pub_date',), 'classes': 'collapse'}),
('attachment', {'fields':('attachment',)}),
),
list_display = ('question', 'pub_date', 'was_published_today'),
list_filter = ,
search_fields = ,
date_hierarchy = 'pub_date',
)

class Choice(meta.Model):
poll = meta.ForeignKey(Poll, edit_inline=meta.TABULAR, num_in_admin=3)
choice = meta.CharField(maxlength=200, core=True)
votes = meta.IntegerField(core=True)

def __repr__(self):
return self.choice

My URLconf is:

from django.conf.urls.defaults import *

info_dict = {
'app_label': 'polls',
'module_name': 'polls',
}

urlpatterns = patterns('',
(r'^$', 'django.views.generic.list_detail.object_list', info_dict),
(r'^(?P<object_id>\d+)/$',
'django.views.generic.list_detail.object_detail', info_dict),
(r'^(?P<object_id>\d+)/results/$',
'django.views.generic.list_detail.object_detail', dict(info_dict,
template_name='polls/results')),
(r'^(?P<poll_id>\d+)/vote/$', 'myproj.apps.polls.views.polls.vote'),
(r'^add/$', 'django.views.generic.create_update.create_object',
dict(info_dict, post_save_redirect="/polls/%(id)s/")),
(r'^(?P<object_id>\d+)/update/$',
'django.views.generic.create_update.update_object', dict(info_dict,
post_save_redirect="/polls/%(object_id)s/")),
)

my polls_form.html template is:

{% block content %}
<h1>Create a polls:</h1>

{% if form.has_errors %}
<h2>Please correct the following error{{ errors|pluralize }}:</h2>
{% endif %}
<table>
<form enctype="multipart/form-data" method="post" action=".">
{% for field in form.fields %}
<tr>
<td>
<label>{{field.field_name}}</label></td>
<td>
{{field}}
</td>
</tr>
{% if field.errors %}<tr><td>*** {{ field.errors|join:", "
}}</td></tr>{% endif %}
{% endfor %}
<tr>
<td>
<input type="submit" />
</td>
</tr>
</form>
</table>

{% endblock %}

As I summited with a file, I always got a error message is "*** This
field is required." under the attachment field. So I checked the
generic source code and compared with admin source code, I found the
code is not very the same, so I made the ticket #816, and as I
submited again, it was successful.

--
I like python!
My Blog:http://www.donews.net/limodouNewEdit Maillist:http://groups.google.com/group/NewEdit

Offline

Board footer

Moderator control

Enjoy the 18th of November
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support