Mercurial > public > madeira
comparison band/views.py @ 71:e2868ad47a1e
For Django 1.4, using the new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 14 Apr 2012 16:40:29 -0500 |
parents | madeira/band/views.py@4579bbb6e053 |
children | 2db040e89285 |
comparison
equal
deleted
inserted
replaced
70:f26cdda0ad8b | 71:e2868ad47a1e |
---|---|
1 """ | |
2 Views for the band application. | |
3 | |
4 """ | |
5 import random | |
6 | |
7 from django.shortcuts import render | |
8 from django.shortcuts import get_object_or_404 | |
9 from photologue.models import Gallery | |
10 from photologue.models import Photo | |
11 | |
12 from band.models import Member, Merchandise, Album | |
13 | |
14 | |
15 def bio(request): | |
16 members = Member.objects.exclude(is_active=0) | |
17 return render(request, 'band/bio.html', {'members': members}) | |
18 | |
19 | |
20 def photos_index(request): | |
21 galleries = Gallery.objects.values('title', 'id').order_by('-id') | |
22 | |
23 photo_ids = Photo.objects.filter(is_public=True).values_list('id', | |
24 flat=True) | |
25 photo_ids = random.sample(photo_ids, 4) | |
26 random_photos = Photo.objects.filter(id__in=photo_ids) | |
27 | |
28 return render(request, 'band/photos.html', { | |
29 'galleries': galleries, | |
30 'random_photos': random_photos, | |
31 }) | |
32 | |
33 | |
34 def photo_detail(request, id): | |
35 gallery = get_object_or_404(Gallery, pk=id) | |
36 photos = gallery.photos.order_by('id') | |
37 | |
38 return render(request, 'band/photo_detail.html', { | |
39 'gallery': gallery, | |
40 'photos': photos, | |
41 }) | |
42 | |
43 | |
44 def buy(request): | |
45 albums = Album.objects.all().order_by('-id') | |
46 merchandise = Merchandise.objects.all().order_by('-id') | |
47 return render(request, 'band/buy.html', { | |
48 'albums': albums, | |
49 'merchandise': merchandise, | |
50 }) | |
51 | |
52 | |
53 def contact(request): | |
54 band = Member.objects.exclude(is_active=0).order_by('order') | |
55 return render(request, 'band/contact.html', { | |
56 'band': band, | |
57 }) |