summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErnesto Rico-Schmidt <e.rico.schmidt@gmail.com>2011-04-06 21:28:59 (GMT)
committerErnesto Rico-Schmidt <e.rico.schmidt@gmail.com>2011-04-06 21:28:59 (GMT)
commit3c5bfc8fe50437e9a8f8b1a259639dc95c56f3d9 (patch)
tree9b5b3cde309906886f40597518cf95836f5329e3
parent45ac409c7861a99526e314dfa5f358e49208c0ab (diff)
tweaked Note administration.
-rw-r--r--program/admin.py26
1 files changed, 25 insertions, 1 deletions
diff --git a/program/admin.py b/program/admin.py
index 5a6ce7f..6c64dd3 100644
--- a/program/admin.py
+++ b/program/admin.py
@@ -1,5 +1,7 @@
from django.contrib import admin
+from datetime import datetime
+
from models import BroadcastFormat, MusicFocus, ShowInformation, ShowTopic, Host, Note, ProgramSlot, Show, TimeSlot
class BroadcastFormatAdmin(admin.ModelAdmin):
@@ -20,10 +22,32 @@ class ShowTopicAdmin(admin.ModelAdmin):
class NoteAdmin(admin.ModelAdmin):
date_hierarchy = 'start'
- list_display = ('title', 'show', 'status')
+ list_display = ('title', 'show', 'start', 'status')
list_filter = ('status',)
ordering = ('timeslot',)
+ def queryset(self, request):
+ qs = super(NoteAdmin, self).queryset(request)
+
+ if request.user.is_superuser:
+ return qs
+ else:
+ return qs.filter(owner=request.user)
+
+ def formfield_for_foreignkey(self, db_field, request, **kwargs):
+ if db_field.name == 'timeslot':
+ if request.user.is_superuser:
+ kwargs['queryset'] = TimeSlot.objects.filter(start__gt=datetime.now)
+ else:
+ shows = request.user.shows.all()
+ kwargs['queryset'] = TimeSlot.objects.filter(show__in=shows, start__gt=datetime.now)
+
+ return super(NoteAdmin, self).formfield_for_foreignkey(db_field, request, **kwargs)
+
+ def save_model(self, request, obj, form, change):
+ obj.owner = request.user
+ obj.save()
+
class TimeSlotInline(admin.TabularInline):
model = TimeSlot