Skip to content

Instantly share code, notes, and snippets.

@philippeowagner
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save philippeowagner/a4aac4c72bd27fed66d0 to your computer and use it in GitHub Desktop.

Select an option

Save philippeowagner/a4aac4c72bd27fed66d0 to your computer and use it in GitHub Desktop.
from django.db import models
import os
import uuid
class MyModel(models.Model):
def generate_new_filename(instance, filename):
f, ext = os.path.splitext(filename)
return '%s%s' % (uuid.uuid4().hex, ext)
title = models.CharField(max_length=100)
picture = models.ImageField(upload_to=generate_new_filename)
def __unicode__(self):
return self.title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment