Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.db import models
- ...
- class Picture(models.Model):
- ...
- pic = models.ImageField(upload_to='tmp')
- ...
- def save(self, *args, **kwargs):
- #saving the picture first, because it must be uploaded and stored first
- super(Picture, self).save(*args, **kwargs)
- #moving picture if needed
- if blablabla:
- import os
- from django.conf import settings
- path = settings.MEDIA_ROOT + somedirname + '/'
- if not os.path.exists(path):
- os.mkdir(path)
- os.rename(self.pic.path, path + self.pic.name.split('/')[-1])
- #self.pic is ImageFieldFile object
- self.pic = somedir + '/' + self.pic.name.split('/')[-1]
- #self.pic is string object
- super(Picture, self).save(*args, **kwargs)
- #now it's again an ImageFieldFile object with new path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement