use unicode_literals in models, admin
[mygpo.git] / mygpo / podcasts / admin.py
bloba1eb2f6d45b185ba3f4227a174d0bbc1df5d9ddb
1 from __future__ import unicode_literals
3 from django.contrib import admin
4 from django.contrib.contenttypes.admin import GenericTabularInline
5 from mygpo.podcasts.models import Podcast, Episode, URL, Slug, Tag, MergedUUID
8 @admin.register(URL)
9 class URLAdmin(admin.ModelAdmin):
10 model = URL
11 list_display = ('url', 'content_type', 'object_id')
12 list_filter = ('content_type', )
15 class URLInline(GenericTabularInline):
16 model = URL
19 class SlugInline(GenericTabularInline):
20 model = Slug
23 class TagInline(GenericTabularInline):
24 model = Tag
27 class MergedUUIDInline(GenericTabularInline):
28 model = MergedUUID
31 @admin.register(Podcast)
32 class PodcastAdmin(admin.ModelAdmin):
33 """ Admin page for podcasts """
35 # configuration for the list view
36 list_display = ('title', 'main_url', )
38 # fetch the podcast's URL for the fields in list_display
39 list_select_related = ('urls', )
41 list_filter = ('language', )
42 search_fields = ('title', 'twitter', '^urls__url', )
44 # configuration for the create / edit view
45 fieldsets = (
46 (None, {
47 'fields': ('id', 'title', 'subtitle', 'description', 'link',
48 'language')
49 }),
50 ('Additional information', {
51 'fields': ('created', 'license', 'flattr_url', 'author', 'twitter',
52 'related_podcasts', )
53 }),
54 ('Podcast Group', {
55 'fields': ('group', 'group_member_name',)
56 }),
57 ('Episodes', {
58 'fields': ('common_episode_title', 'latest_episode_timestamp',
59 'content_types', )
60 }),
61 ('Feed updates', {
62 'fields': ('outdated', 'new_location', 'last_update', )
63 }),
64 ('Admin', {
65 'fields': ('restrictions', 'hub', )
66 }),
69 inlines = [
70 URLInline,
71 SlugInline,
72 TagInline,
73 MergedUUIDInline,
76 raw_id_fields = ('related_podcasts', )
78 readonly_fields = ('id', 'created', 'last_update', )
80 def main_url(self, podcast):
81 url = podcast.urls.first()
82 if url is None:
83 return ''
85 return url.url
88 @admin.register(Episode)
89 class EpisodeAdmin(admin.ModelAdmin):
90 """ Admin page for episodes """
92 # configuration for the list view
93 list_display = ('title', 'podcast_title', 'main_url', )
95 # fetch the episode's podcast and URL for the fields in list_display
96 list_select_related = ('podcast', 'urls', )
98 list_filter = ('language', )
99 search_fields = ('title', '^urls__url')
101 # configuration for the create / edit view
102 fieldsets = (
103 (None, {
104 'fields': ('id', 'title', 'subtitle', 'description', 'link',
105 'language', 'guid', 'released', 'podcast', )
107 ('Additional information', {
108 'fields': ('created', 'license', 'flattr_url', 'author', 'content',
109 'listeners', )
111 ('Media file', {
112 'fields': ('duration', 'filesize', 'content_types', 'mimetypes', )
114 ('Feed updates', {
115 'fields': ('outdated', 'last_update', )
119 inlines = [
120 URLInline,
121 SlugInline,
122 MergedUUIDInline,
125 raw_id_fields = ('podcast', )
127 readonly_fields = ('id', 'created', 'last_update', )
129 def podcast_title(self, episode):
130 return episode.podcast.title
132 def main_url(self, episode):
133 return episode.urls.first().url