2005/11/16, Adrian Holovaty <[EMAIL PROTECTED]>:
>
> On 11/16/05, limodou <[EMAIL PROTECTED]> 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 = ['pub_date'],
            search_fields = ['question'],
            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/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit

Reply via email to