Here is my model:

class Book(models.Model):
    title = models.CharField(max_length=150)
    category = models.CharField(max_length=50)
    description = models.CharField(max_length=2000)
    image1 = models.ImageField(upload_to='img/bk', blank=True)
    image2 = models.ImageField(upload_to='img/bk', blank=True)
    image3 = models.ImageField(upload_to='img/bk', blank=True)

I want to create a form to add/edit a book which can upload image
files (I want to make sure it is an image file and individual image
file is within size limit, e.g. 500kb, and dimension limit, e.g.
800X600 px).

I don't think I can use ModelForm because this validation requirement,
also because I want to automatically set the category value for the
form on the fly. But don't know 1) how to save uploaded images in view
along with the new Model object. 2) how to do validation on the
uploaded image files.

I found a close reference:

http://www.oluyede.org/blog/2007/03/18/django-image-uploading-validation-and-newforms/

But it reads: "This post is outdated now - if you’re using the latest
django, do not follow this post." I don't know what to follow for
Django 1.0.2 that I am using. The Django document on forms:
http://docs.djangoproject.com/en/dev/topics/forms/
does not even mention how to ceate a form for ImageField in Model. Can
anyone help with some code snippets? Thanks.


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

Reply via email to