create bash script: install_latest_boto.sh:
#install latest boto from source cd /home/ubuntu/ sudo mkdir boto_temp cd boto_temp sudo git clone git://github.com/boto/boto.git cd boto sudo python setup.py install
in Django settings - the default django repository will be s3:
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage' STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage' AWS_S3_FILE_OVERWRITE = False
on your models.py:
class MyBaseModel(models.Model): class Meta: abstract = True @staticmethod def get_upload_path(instance, filename): if hasattr(instance, 'get_upload_folder'): return os.path.join(instance.get_upload_folder(), filename) else: raise Exception('Upload Folder is missing') class User(MyBaseModel): name = models.CharField(max_length=100) email = models.EmailField(max_length=255, unique=True) image = models.ImageField(upload_to=MyBaseModel.get_upload_path, default=None, blank=True, max_length=200) def get_upload_folder(self): upload_folder = 'users/images/orig' return upload_folder
source share