Since Heroku expires in 30 seconds, I have to upload the files sent by the user directly to S3. After I upload them to S3, I insert a record into the database to record that I received this file. Here is my model:
class UserUploadedFile(models.Model): id = models.AutoField(primary_key=True) uid = models.ForeignKey('auth.user', editable=False, db_column='uid') filepath = models.FileField(storage=S3BotoStorage(bucket='whatever'), upload_to='/')
But since Boto is automatically called when I call save () like this, Boto is called to process the file:
file = UserUploadedFile(uid=request.user, filepath=key) file.save()
(I need the file path to be processed by Boto, so I can get its URL, filesize and c. Later, so I can't turn the file path into a string.)
In any case, I tried overriding save () to get around Boto:
def save(self, *args, **kwargs): filepath = self.filepath if self.filepath: self.filepath = '' super(UserUploadedFile, self).save(*args, **kwargs) self.raw('UPDATE mysite_useruploadedfile SET filepath=%s WHERE id=%d', [filepath, self.pk])
But I get this error:
'UserUploadedFile' object has no attribute 'raw'
I'm not sure how to call raw () in this context, clearly ...
... but my main question is whether this is the right way to get around the storage mechanism when I write to this table, or if there is a cleaner way to do this .
Thanks!