Django Library PyGal
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

admin.py 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. from django.contrib import admin
  2. from .models import Item, Tag, TYPE_AUDIO, TYPE_FOLDER, TYPE_IMAGE, TYPE_VIDEO
  3. class ItemAdmin(admin.ModelAdmin):
  4. list_display = ('rel_path', 'type', )
  5. search_fields = ('rel_path', )
  6. readonly_fields = (
  7. 'rel_path',
  8. 'type',
  9. 'artist_c',
  10. 'album_c',
  11. 'year_c',
  12. 'title_c',
  13. 'track_c',
  14. 'duration_c',
  15. 'genre_c',
  16. 'bitrate_c',
  17. 'num_audio_c',
  18. 'num_folders_c',
  19. 'num_images_c',
  20. 'num_other_c',
  21. 'num_videos_c',
  22. 'sil_c',
  23. 'camera_c',
  24. 'width_c',
  25. 'height_c',
  26. 'exposure_program_c',
  27. 'exposure_time_c',
  28. 'iso_c',
  29. 'f_number_c',
  30. 'focal_length_c',
  31. 'flash_c',
  32. 'lon_c',
  33. 'lat_c',
  34. 'orientation_c',
  35. 'ratio_c'
  36. )
  37. list_filter = (
  38. ('type', admin.ChoicesFieldListFilter),
  39. ('public_access', admin.BooleanFieldListFilter),
  40. ('read_access', admin.RelatedFieldListFilter),
  41. ('modify_access', admin.RelatedFieldListFilter),
  42. )
  43. def get_fields(self, request, obj=None):
  44. if obj is not None:
  45. rv = ['rel_path', 'type', 'datetime_c']
  46. if obj.type == TYPE_FOLDER:
  47. rv += ['public_access', 'read_access', 'modify_access']
  48. else:
  49. rv += ['favourite_of']
  50. rv += ['size_c', 'uid_c', 'settings_c', 'data_version_c']
  51. if obj.type == TYPE_AUDIO:
  52. rv += [
  53. 'artist_c',
  54. 'album_c',
  55. 'year_c',
  56. 'title_c',
  57. 'track_c',
  58. 'duration_c',
  59. 'genre_c',
  60. 'bitrate_c',
  61. ]
  62. if obj.type == TYPE_FOLDER:
  63. rv += [
  64. 'num_folders_c',
  65. 'num_audio_c',
  66. 'num_images_c',
  67. 'num_other_c',
  68. 'num_videos_c',
  69. 'sil_c',
  70. ]
  71. if obj.type == TYPE_IMAGE:
  72. rv += [
  73. 'camera_c',
  74. 'width_c',
  75. 'height_c',
  76. 'lon_c',
  77. 'lat_c',
  78. 'exposure_program_c',
  79. 'exposure_time_c',
  80. 'iso_c',
  81. 'focal_length_c',
  82. 'f_number_c',
  83. 'flash_c',
  84. 'orientation_c',
  85. ]
  86. if obj.type == TYPE_VIDEO:
  87. rv += [
  88. 'duration_c',
  89. 'width_c',
  90. 'height_c',
  91. 'ratio_c'
  92. ]
  93. return rv
  94. else:
  95. return admin.ModelAdmin.get_fields(self, request, obj=obj)
  96. class TagAdmin(admin.ModelAdmin):
  97. list_display = ('item', 'text', )
  98. search_fields = ('item__rel_path', 'text', )
  99. admin.site.register(Item, ItemAdmin)
  100. admin.site.register(Tag, TagAdmin)