Hi,

I'm new to Django and programming in general. I've been trying to
create a form that simply uploads images and saves them to a app
folder. I'm using MySql with Django svn. Here's my model:

class Images(models.Model):
    prim = models.AutoField(primary_key=True, db_column='PRIM') #
Field name made lowercase.
    photos = models.ImageField(db_column='PHOTOS', upload_to='img',
blank=True) # Field name made lowercase.
    items = models.CharField(max_length=255, db_column='ITEMS',
blank=True) # Field name made lowercase.
    date = models.DateField(null=True, db_column='DATE', blank=True) #
Field name made lowercase.
    class Meta:
        db_table = u'IMAGES'

Here's my view:
class PictureForm(ModelForm):
   class Meta:
       model=Images
       exclude = ('prim',)

def image_loads(request):
    form=PictureForm()
    if request.method=='POST':
        form=PictureForm(request.POST,  request.FILES)
        if form.is_multipart():
            form.save()
            form=PictureForm()
            return render_to_response('photos.html', {'form':form,  },
context_instance = RequestContext(request))

    return render_to_response('photos.html', {'form':form,  },
context_instance = RequestContext(request))

Here's photo.html:

{%extends "base.html" %}

{%block head%}
{%endblock%}
{%block content%}

<form enctype="multipart/form-data" method="post" action="/photos/">

{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
{% if comment %}
{{comment}}
{%endif%}

{%endblock%}

Here's the error message:
Environment:

Request Method: POST
Request URL: http://localhost:8000/photos/
Django Version: 1.1 beta 1 SVN-10891
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'orders1.onhand',
 'registration']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.csrf.middleware.CsrfMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
  92.                 response = callback(request, *callback_args,
**callback_kwargs)
File "/home/malcolm/data1/orders1/../orders1/onhand/views.py" in
image_loads
  49.             form.save()
File "/usr/lib/python2.5/site-packages/django/forms/models.py" in save
  407.                              fail_message, commit,
exclude=self._meta.exclude)
File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
save_instance
  42.                          " validate." % (opts.object_name,
fail_message))

Exception Type: ValueError at /photos/
Exception Value: The Images could not be created because the data
didn't validate.

Any help or suggestions would be greatly appreciated. Thanks.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to