Mercurial > public > sg101
comparison downloads/admin.py @ 581:ee87ea74d46b
For Django 1.4, rearranged project structure for new manage.py.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 05 May 2012 17:10:48 -0500 |
parents | gpp/downloads/admin.py@6144023ebea8 |
children | 0dd84cff2477 |
comparison
equal
deleted
inserted
replaced
580:c525f3e0b5d0 | 581:ee87ea74d46b |
---|---|
1 """ | |
2 This file contains the automatic admin site definitions for the downloads models. | |
3 """ | |
4 import datetime | |
5 | |
6 from django.contrib import admin | |
7 from django.conf import settings | |
8 | |
9 from downloads.models import PendingDownload | |
10 from downloads.models import Download | |
11 from downloads.models import Category | |
12 from downloads.models import AllowedExtension | |
13 from downloads.models import VoteRecord | |
14 | |
15 | |
16 class CategoryAdmin(admin.ModelAdmin): | |
17 list_display = ('title', 'slug', 'description', 'count') | |
18 prepopulated_fields = {'slug': ('title', )} | |
19 readonly_fields = ('count', ) | |
20 | |
21 | |
22 class PendingDownloadAdmin(admin.ModelAdmin): | |
23 exclude = ('html', ) | |
24 list_display = ('title', 'user', 'category', 'date_added', 'ip_address', 'size') | |
25 ordering = ('date_added', ) | |
26 raw_id_fields = ('user', ) | |
27 readonly_fields = ('update_date', ) | |
28 | |
29 actions = ('approve_downloads', ) | |
30 | |
31 def approve_downloads(self, request, qs): | |
32 for pending_dl in qs: | |
33 dl = Download( | |
34 title=pending_dl.title, | |
35 category=pending_dl.category, | |
36 description=pending_dl.description, | |
37 html=pending_dl.html, | |
38 file=pending_dl.file, | |
39 user=pending_dl.user, | |
40 date_added=datetime.datetime.now(), | |
41 ip_address=pending_dl.ip_address, | |
42 hits=0, | |
43 average_score=0.0, | |
44 total_votes=0, | |
45 is_public=True) | |
46 dl.save() | |
47 | |
48 # If we don't do this, the actual file will be deleted when | |
49 # the pending download is deleted. | |
50 pending_dl.file = None | |
51 pending_dl.delete() | |
52 | |
53 approve_downloads.short_description = "Approve selected downloads" | |
54 | |
55 | |
56 class DownloadAdmin(admin.ModelAdmin): | |
57 exclude = ('html', ) | |
58 list_display = ('title', 'user', 'category', 'date_added', 'ip_address', | |
59 'hits', 'average_score', 'size', 'is_public') | |
60 list_filter = ('date_added', 'is_public', 'category') | |
61 list_editable = ('is_public', ) | |
62 date_hierarchy = 'date_added' | |
63 ordering = ('-date_added', ) | |
64 search_fields = ('title', 'description', 'user__username') | |
65 raw_id_fields = ('user', ) | |
66 readonly_fields = ('update_date', ) | |
67 save_on_top = True | |
68 | |
69 | |
70 class VoteRecordAdmin(admin.ModelAdmin): | |
71 list_display = ('user', 'download', 'vote_date') | |
72 list_filter = ('user', 'download') | |
73 date_hierarchy = 'vote_date' | |
74 | |
75 | |
76 admin.site.register(PendingDownload, PendingDownloadAdmin) | |
77 admin.site.register(Download, DownloadAdmin) | |
78 admin.site.register(Category, CategoryAdmin) | |
79 admin.site.register(AllowedExtension) | |
80 admin.site.register(VoteRecord, VoteRecordAdmin) | |
81 |