Skip to content

Instantly share code, notes, and snippets.

@fandrefh
Created August 1, 2014 13:10
Show Gist options
  • Save fandrefh/bf3644fd8fdf91d0f28a to your computer and use it in GitHub Desktop.
Save fandrefh/bf3644fd8fdf91d0f28a to your computer and use it in GitHub Desktop.
class Campaign(models.Model):
def generate_new_filename(instance, filename):
ext = filename.split('.')[-1]
filename = '%s.%s' % (uuid.uuid4(), ext)
return os.path.join('images', filename)
user = models.ForeignKey(User, blank=True, null=True)
title = models.CharField(u'Título da sua Campanha', max_length=50)
goal = models.DecimalField(u'Meta R$', max_digits=15, decimal_places=2, help_text='De quanto você precisa?')
donations = models.DecimalField(u'Doação de R$', max_digits=5, decimal_places=2, help_text='A partir de quanto gostaria de receber.');
image = models.ImageField(u'Envie uma imagem', upload_to=generate_new_filename, help_text='Envie uma bela imagem para sua campanha.')
message = models.TextField(u'Fale sobre sua campanha', help_text='Faça uma boa descrição da sua campanha')
created_at = models.DateTimeField(auto_now_add=True)
def real_coin(self):
setlocale(LC_ALL, 'pt_BR.UTF-8')
return coin(self.goal, grouping=True)
real_coin.short_description = 'Meta: '
def __unicode__(self):
return self.title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment