Mercurial > public > sg101
comparison gpp/banners/models.py @ 558:9a68fd3bd8a5
Creating a simple banner / ad campaign application, initially as a RFB / SG101
tie-in.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 02 Feb 2012 18:56:48 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
557:7247a406f92b | 558:9a68fd3bd8a5 |
---|---|
1 """ | |
2 Models for the banners application. | |
3 | |
4 """ | |
5 import datetime | |
6 | |
7 from django.db import models | |
8 | |
9 | |
10 class Campaign(models.Model): | |
11 """ | |
12 A model to represent an ad or banner campaign. | |
13 | |
14 """ | |
15 name = models.CharField(max_length=128) | |
16 slug = models.SlugField() | |
17 creation_date = models.DateTimeField(blank=True) | |
18 | |
19 def __unicode__(self): | |
20 return self.name | |
21 | |
22 class Meta: | |
23 ordering = ['name'] | |
24 | |
25 def save(self, *args, **kwargs): | |
26 if not self.pk and not self.creation_date: | |
27 self.creation_date = datetime.datetime.now() | |
28 | |
29 super(Campaign, self).save(*args, **kwargs) | |
30 | |
31 | |
32 def banner_upload_to(instance, filename): | |
33 """ | |
34 An "upload_to" function for the Banner model. | |
35 | |
36 """ | |
37 return "banners/%s/%s" % (instance.campaign.slug, filename) | |
38 | |
39 | |
40 class Banner(models.Model): | |
41 """ | |
42 A model to represent a banner. | |
43 | |
44 """ | |
45 campaign = models.ForeignKey(Campaign) | |
46 image = models.ImageField(upload_to=banner_upload_to) | |
47 description = models.CharField(max_length=128) | |
48 creation_date = models.DateTimeField(blank=True) | |
49 | |
50 def __unicode__(self): | |
51 return self.description | |
52 | |
53 class Meta: | |
54 ordering = ['-creation_date'] | |
55 | |
56 def save(self, *args, **kwargs): | |
57 if not self.pk and not self.creation_date: | |
58 self.creation_date = datetime.datetime.now() | |
59 | |
60 super(Banner, self).save(*args, **kwargs) |