On Jan 13, 12:06 pm, Ty <brownellty...@gmail.com> wrote: > I've started creating a photo blog project to get familiar with Python > and Django. I'm using Python 2.6.1 and Django 1.0.2. I'm working on > the models and the administration first, before I tackle the front end > side of the site. I have everything working fine, for the exception of > an image upload field in the administration. > > I assume I'm just going to have to add an "ImageField" in the model. > That I get, however, every time a new image is uploaded I want to > resize and save a few copies of the images for thumbnail use, and I > don't know how to go about extending an administration form like that. > > I've been looking around and I've seen the save method in the model > class. For example I'm using this to come up with the post title slug: > > def save(self): > self.name_slug = re.sub('[^a-zA-Z0-9]', '_', self.name).strip > ('_').lower() > self.name_slug = re.sub('[-]+', '_', self.name_slug) > super(Entry, self).save() > > Should I add the image manipulation code in the save method? What is > the best way to go about this issue?
Yeah I would (and have) done that type of stuff there. See also the documentation for the admin interface and overriding the save_model method on admin.ModelAdmin. You can hang custom behavior there also, if you only want that behavior when you save a model from the admin interface. > > On another note, is there a good resource for image manipulation in > Python? I've used the PIL (Python Imaging Library) to manipulate images. Be aware that there are other django pluggable applications that you could use also: search for django Photologue, django-thumbs, and django-sorl. It is fairly easy to manipulate images with PIL so I just rolled my own. I used Photologue in a previous project, it is a fantastic full-blown gallery app for django. Have fun! BN --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---