Mercurial > public > madeira
comparison mysite/band/models.py @ 1:0dcfcdf50c62
Initial import of Madeira project from the private repository.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 06 Apr 2009 03:10:59 +0000 |
parents | |
children | e602b5302b94 |
comparison
equal
deleted
inserted
replaced
0:df0370bfe3f0 | 1:0dcfcdf50c62 |
---|---|
1 from django.db import models | |
2 from django.contrib.localflavor.us.models import USStateField | |
3 from django.contrib.localflavor.us.models import PhoneNumberField | |
4 | |
5 from mysite.photologue.models import Photo | |
6 import datetime | |
7 import random | |
8 import string | |
9 | |
10 ####################################################################### | |
11 | |
12 class SiteConfig(models.Model): | |
13 band_name = models.CharField(max_length = 50) | |
14 url = models.URLField(verify_exists = False, max_length = 200) | |
15 contact_email = models.EmailField() | |
16 ordering_info = models.TextField(help_text = 'Enter instructions on how to order merchandise here') | |
17 intro_text = models.TextField(help_text = 'This text appears on the home page.') | |
18 intro_photo = models.ForeignKey(Photo) | |
19 | |
20 def __unicode__(self): | |
21 return self.band_name | |
22 | |
23 class Meta: | |
24 verbose_name = "Site Configuration" | |
25 verbose_name_plural = "Site Configuration" | |
26 | |
27 ####################################################################### | |
28 | |
29 class Member(models.Model): | |
30 name = models.CharField(max_length = 50, db_index = True) | |
31 nickname = models.CharField(max_length = 50, blank = True) | |
32 instrument = models.CharField(max_length = 255) | |
33 bio = models.TextField(blank = True) | |
34 photo = models.FileField(upload_to = 'images/bio/', blank = True) | |
35 order = models.SmallIntegerField(help_text = '''Controls order of display on the bio page, lower numbers displayed | |
36 first''') | |
37 is_active = models.BooleanField(db_index = True) | |
38 start_date = models.DateField() | |
39 end_date = models.DateField(blank = True, help_text = 'Only used if the member is not active', | |
40 default = datetime.date(1985, 1, 1)) | |
41 email = models.EmailField() | |
42 | |
43 def __unicode__(self): | |
44 return self.name | |
45 | |
46 class Meta: | |
47 ordering = ('-is_active', 'name') | |
48 | |
49 ####################################################################### | |
50 | |
51 class Gear(models.Model): | |
52 member = models.ForeignKey(Member) | |
53 item = models.CharField(max_length = 255) | |
54 | |
55 def __unicode__(self): | |
56 return self.item | |
57 | |
58 class Meta: | |
59 verbose_name_plural = 'Gear List' | |
60 | |
61 ####################################################################### | |
62 | |
63 class State(models.Model): | |
64 name = models.CharField(max_length = 16) | |
65 abbrev = USStateField() | |
66 | |
67 class Meta: | |
68 ordering = ('name', ) | |
69 | |
70 def __unicode__(self): | |
71 return self.name | |
72 | |
73 ####################################################################### | |
74 | |
75 class City(models.Model): | |
76 name = models.CharField(max_length = 50) | |
77 state = models.ForeignKey(State, null = True, blank = True) | |
78 | |
79 class Meta: | |
80 verbose_name_plural = 'Cities' | |
81 ordering = ('name', ) | |
82 | |
83 def __unicode__(self): | |
84 if self.state: | |
85 return self.name + u', ' + self.state.abbrev | |
86 return self.name | |
87 | |
88 ####################################################################### | |
89 | |
90 class Venue(models.Model): | |
91 name = models.CharField(max_length = 50, db_index = True) | |
92 url = models.URLField(verify_exists = False, blank = True) | |
93 address = models.CharField(max_length = 255, blank = True) | |
94 phone = PhoneNumberField(help_text = "Format: XXX-XXX-XXXX", blank = True) | |
95 city = models.ForeignKey(City) | |
96 | |
97 class Meta: | |
98 ordering = ('name', ) | |
99 | |
100 def __unicode__(self): | |
101 return self.name | |
102 | |
103 ####################################################################### | |
104 | |
105 class Band(models.Model): | |
106 name = models.CharField(max_length = 64) | |
107 url = models.URLField(verify_exists = False, blank = True) | |
108 | |
109 class Meta: | |
110 ordering = ('name', ) | |
111 | |
112 def __unicode__(self): | |
113 return self.name | |
114 | |
115 ####################################################################### | |
116 | |
117 class Gig(models.Model): | |
118 title = models.CharField(max_length = 50, blank = True, help_text = "Optional; e.g. Some Festival") | |
119 url = models.URLField(verify_exists = False, blank = True, help_text = "Optional; e.g. Some Festival's Website") | |
120 date = models.DateField(db_index = True) | |
121 time = models.TimeField(null = True, blank = True) | |
122 venue = models.ForeignKey(Venue, null = True, blank = True) | |
123 notes = models.TextField(blank = True) | |
124 bands = models.ManyToManyField(Band, blank = True) | |
125 flyer = models.ForeignKey(Photo, null = True, blank = True) | |
126 | |
127 def __unicode__(self): | |
128 if self.title: | |
129 return u'%s %s %s' % (self.date.strftime('%m/%d/%Y'), self.title, self.venue.name) | |
130 elif self.venue: | |
131 return u'%s %s' % (self.date.strftime('%m/%d/%Y'), self.venue.name) | |
132 else: | |
133 return u'' + self.date.strftime('%m/%d/%Y') | |
134 | |
135 class Meta: | |
136 ordering = ('-date', 'time') | |
137 | |
138 ####################################################################### | |
139 | |
140 class News(models.Model): | |
141 title = models.CharField(max_length = 64, blank = True) | |
142 date = models.DateField(db_index = True) | |
143 author = models.CharField(max_length = 50, blank = True) | |
144 text = models.TextField() | |
145 markup_enabled = models.BooleanField(default = True, | |
146 help_text = 'Check this box to allow Textile style markup in the text field') | |
147 photo = models.FileField(upload_to = 'images/news/%Y/%m/%d/', blank = True) | |
148 photo_caption = models.CharField(max_length = 50, blank = True) | |
149 | |
150 def __unicode__(self): | |
151 return u'%s %s' % (self.date.strftime('%m/%d/%Y'), self.title) | |
152 | |
153 class Meta: | |
154 ordering = ('-date', ) | |
155 verbose_name_plural = "News" | |
156 | |
157 ####################################################################### | |
158 | |
159 class Article(models.Model): | |
160 title = models.CharField(max_length = 64) | |
161 date = models.DateField(db_index = True) | |
162 text = models.TextField() | |
163 markup_enabled = models.BooleanField(default = True, | |
164 help_text = 'Check this box to allow Textile style markup in the text field') | |
165 source = models.TextField(help_text = '''Enter the source/author for the article, copyright info, etc; it will appear under | |
166 the article.''') | |
167 url = models.URLField(blank = True, help_text = 'Link to original article; optional') | |
168 pdf = models.FileField(upload_to = 'pdf/articles/%Y/%m/%d/', blank = True, | |
169 help_text = '''If you want to make the original article available as a PDF download, you may upload it | |
170 here.''') | |
171 | |
172 def __unicode__(self): | |
173 return self.title | |
174 | |
175 class Meta: | |
176 ordering = ('date', ) | |
177 | |
178 ####################################################################### | |
179 | |
180 class Mp3_Set(models.Model): | |
181 date = models.DateField(auto_now_add = True, editable = False) | |
182 title = models.CharField(max_length = 64) | |
183 text = models.TextField() | |
184 | |
185 def __unicode__(self): | |
186 return self.title | |
187 | |
188 class Meta: | |
189 ordering = ('date', ) | |
190 verbose_name = "MP3 Set" | |
191 | |
192 ####################################################################### | |
193 | |
194 class Mp3(models.Model): | |
195 mp3_set = models.ForeignKey(Mp3_Set) | |
196 title = models.CharField(max_length = 64) | |
197 desc = models.CharField(max_length = 128, blank = True) | |
198 file = models.FileField(upload_to = 'mp3s/%Y/%m/%d/') | |
199 slug = models.SlugField(unique = True) | |
200 | |
201 def __unicode__(self): | |
202 return self.title | |
203 | |
204 class Meta: | |
205 ordering = ('title', ) | |
206 verbose_name = "MP3" | |
207 | |
208 ####################################################################### | |
209 | |
210 class Video_Set(models.Model): | |
211 date = models.DateField(auto_now_add = True, editable = False) | |
212 title = models.CharField(max_length = 64) | |
213 text = models.TextField() | |
214 | |
215 def __unicode__(self): | |
216 return self.title | |
217 | |
218 class Meta: | |
219 ordering = ('date', ) | |
220 verbose_name = "Video Set" | |
221 | |
222 ####################################################################### | |
223 | |
224 class Video(models.Model): | |
225 video_set = models.ForeignKey(Video_Set) | |
226 title = models.CharField(max_length = 64) | |
227 embed_code = models.CharField(max_length = 1024) | |
228 | |
229 def __unicode__(self): | |
230 return self.title | |
231 | |
232 class Meta: | |
233 ordering = ('title', ) | |
234 | |
235 ####################################################################### | |
236 | |
237 class Record_Label(models.Model): | |
238 name = models.CharField(max_length = 64) | |
239 url = models.URLField(verify_exists = False, max_length = 200) | |
240 | |
241 def __unicode__(self): | |
242 return self.name | |
243 | |
244 class Meta: | |
245 verbose_name = 'Record Label' | |
246 | |
247 ####################################################################### | |
248 | |
249 class Album(models.Model): | |
250 title = models.CharField(max_length = 64) | |
251 photo = models.ForeignKey(Photo) | |
252 desc = models.TextField(blank = True) | |
253 | |
254 def __unicode__(self): | |
255 return self.title | |
256 | |
257 class Meta: | |
258 pass | |
259 | |
260 ####################################################################### | |
261 | |
262 class Album_Track(models.Model): | |
263 album = models.ForeignKey(Album) | |
264 track_number = models.SmallIntegerField() | |
265 track_name = models.CharField(max_length = 64) | |
266 | |
267 def __unicode__(self): | |
268 return self.track_name | |
269 | |
270 class Meta: | |
271 verbose_name = 'Album Track' | |
272 ordering = ('album', 'track_number', ) | |
273 | |
274 ####################################################################### | |
275 | |
276 class Label_Release(models.Model): | |
277 record_label = models.ForeignKey(Record_Label) | |
278 album = models.ForeignKey(Album) | |
279 catalog_number = models.CharField(max_length = 32) | |
280 release_date = models.DateField() | |
281 | |
282 def __unicode__(self): | |
283 return u'%s %s %s' % (self.record_label.name, self.album.title, self.catalog_number) | |
284 | |
285 class Meta: | |
286 verbose_name = 'Label Release' | |
287 | |
288 ####################################################################### | |
289 | |
290 class Album_Merchant(models.Model): | |
291 album = models.ForeignKey(Album) | |
292 name = models.CharField(max_length = 64) | |
293 url = models.URLField(verify_exists = False, max_length = 200) | |
294 | |
295 def __unicode__(self): | |
296 return u'%s (%s)' % (self.name, self.album.title) | |
297 | |
298 class Meta: | |
299 verbose_name = 'Album Merchant' | |
300 ordering = ('name', ) | |
301 | |
302 ####################################################################### | |
303 | |
304 class Merchandise(models.Model): | |
305 name = models.CharField(max_length = 64) | |
306 desc = models.TextField() | |
307 price = models.DecimalField(max_digits = 5, decimal_places = 2) | |
308 in_stock = models.BooleanField() | |
309 photo = models.ForeignKey(Photo) | |
310 | |
311 def __unicode__(self): | |
312 return self.name | |
313 | |
314 class Meta: | |
315 verbose_name_plural = "Merchandise" | |
316 | |
317 ####################################################################### | |
318 | |
319 class Fan(models.Model): | |
320 statusCodes = (('P', 'Pending'), ('A', 'Active'), ('L', 'Leaving')) | |
321 keyLength = 16 | |
322 | |
323 name = models.CharField(max_length = 32, blank = True) | |
324 email = models.EmailField(db_index = True) | |
325 location = models.CharField(max_length = 64, blank = True) | |
326 status = models.CharField(max_length = 1, choices = statusCodes, default = 'A', | |
327 editable = False, db_index = True) | |
328 key = models.CharField(max_length = keyLength, editable = False, blank = True, db_index = True) | |
329 status_date = models.DateField(default = datetime.date.today, editable = False, db_index = True) | |
330 | |
331 def __unicode__(self): | |
332 if self.name: | |
333 return u'%s <%s>' % (self.name, self.email) | |
334 return self.email | |
335 | |
336 class Meta: | |
337 ordering = ('name', 'email') | |
338 | |
339 def setPending(self): | |
340 self.status = 'P' | |
341 self.status_date = datetime.date.today() | |
342 self.genKey() | |
343 | |
344 def setActive(self): | |
345 self.status = 'A' | |
346 self.status_date = datetime.date.today() | |
347 | |
348 def setLeaving(self): | |
349 self.status = 'L' | |
350 self.status_date = datetime.date.today() | |
351 self.genKey() | |
352 | |
353 def isPending(self): | |
354 return self.status == 'P' | |
355 | |
356 def isLeaving(self): | |
357 return self.status == 'L' | |
358 | |
359 def isActive(self): | |
360 return self.status == 'A' | |
361 | |
362 def current_status(self): | |
363 if self.status == 'P': | |
364 return 'Pending' | |
365 elif self.status == 'L': | |
366 return 'Leaving' | |
367 elif self.status == 'A': | |
368 return 'Active' | |
369 else: | |
370 return 'Unknown' | |
371 | |
372 def genKey(self): | |
373 self.key = ''.join(random.sample(string.ascii_letters + string.digits, self.keyLength)) | |
374 |