Skip to content

Instantly share code, notes, and snippets.

Created October 1, 2014 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/70d6740afcb678c7b0f8 to your computer and use it in GitHub Desktop.
Save anonymous/70d6740afcb678c7b0f8 to your computer and use it in GitHub Desktop.
# In the console, this is all that's printed:
# [01/Oct/2014 00:51:33] "POST /StubAcceptFile HTTP/1.1" 500 9935
SETTINGS:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
MODEL:
class Uploaded_File(models.Model):
def file_destination(instance, filename):
return 'user_uploads/' + instance.generated_id
generated_id = models.CharField(max_length=25)
uploaded_file = models.FileField(upload_to=file_destination)
VIEW:
def StubAcceptFile(HttpRequest):
file_data = HttpRequest.FILES["uploaded_excel_file"]
file_id = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits*2) for x in range(25))
new_uploaded_file = Uploaded_File(uploaded_file=file_data, generated_id=file_id)
new_uploaded_file.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment