from django.contrib import admin from .models import Item, Tag, TYPE_AUDIO, TYPE_FOLDER, TYPE_IMAGE, TYPE_VIDEO class ItemAdmin(admin.ModelAdmin): list_display = ('rel_path', 'type', ) search_fields = ('rel_path', ) readonly_fields = ( 'rel_path', 'type', 'artist_c', 'album_c', 'year_c', 'title_c', 'track_c', 'duration_c', 'genre_c', 'bitrate_c', 'num_audio_c', 'num_folders_c', 'num_images_c', 'num_other_c', 'num_videos_c', 'sil_c', 'camera_c', 'width_c', 'height_c', 'exposure_program_c', 'exposure_time_c', 'iso_c', 'f_number_c', 'focal_length_c', 'flash_c', 'lon_c', 'lat_c', 'orientation_c', 'ratio_c' ) list_filter = ( ('type', admin.ChoicesFieldListFilter), ('public_access', admin.BooleanFieldListFilter), ('read_access', admin.RelatedFieldListFilter), ('modify_access', admin.RelatedFieldListFilter), ) def get_fields(self, request, obj=None): if obj is not None: rv = ['rel_path', 'type', 'datetime_c'] if obj.type == TYPE_FOLDER: rv += ['public_access', 'read_access', 'modify_access'] else: rv += ['favourite_of'] rv += ['size_c', 'uid_c', 'settings_c', 'data_version_c'] if obj.type == TYPE_AUDIO: rv += [ 'artist_c', 'album_c', 'year_c', 'title_c', 'track_c', 'duration_c', 'genre_c', 'bitrate_c', ] if obj.type == TYPE_FOLDER: rv += [ 'num_folders_c', 'num_audio_c', 'num_images_c', 'num_other_c', 'num_videos_c', 'sil_c', ] if obj.type == TYPE_IMAGE: rv += [ 'camera_c', 'width_c', 'height_c', 'lon_c', 'lat_c', 'exposure_program_c', 'exposure_time_c', 'iso_c', 'focal_length_c', 'f_number_c', 'flash_c', 'orientation_c', ] if obj.type == TYPE_VIDEO: rv += [ 'duration_c', 'width_c', 'height_c', 'ratio_c' ] return rv else: return admin.ModelAdmin.get_fields(self, request, obj=obj) class TagAdmin(admin.ModelAdmin): list_display = ('item', 'text', ) search_fields = ('item__rel_path', 'text', ) admin.site.register(Item, ItemAdmin) admin.site.register(Tag, TagAdmin)