admin.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. from django.contrib import admin
  2. from newsroom.models import *
  3. from newsroom.forms import *
  4. from django.contrib.contenttypes import generic
  5. #from genericadmin.admin import GenericAdminModelAdmin
  6. from markitup.widgets import AdminMarkItUpWidget
  7. class AuthorAdmin(admin.ModelAdmin):
  8. prepopulated_fields={"slug": ("name",)}
  9. list_display = ('type', 'name', 'created', 'user',)
  10. admin.site.register(Author, AuthorAdmin)
  11. class DatelineAdmin(admin.ModelAdmin):
  12. prepopulated_fields={"slug": ("title",)}
  13. admin.site.register(Dateline, DatelineAdmin)
  14. class EditorialTypeAdmin(admin.ModelAdmin):
  15. prepopulated_fields={"slug": ("name",)}
  16. admin.site.register(EditorialType, EditorialTypeAdmin)
  17. class EditorialAdmin(admin.ModelAdmin):
  18. prepopulated_fields={"slug": ("print_hed",)}
  19. admin.site.register(Editorial, EditorialAdmin)
  20. class ArchiveSectionAdmin(admin.ModelAdmin):
  21. save_on_top=True
  22. prepopulated_fields={"slug": ("title",)}
  23. filter_horizontal=('stories', 'galleries', 'photos', 'pdf_documents', 'editorials')
  24. date_hierarchy='published_on'
  25. list_filter = ('paper', 'dateline', )
  26. search_fields = ('title','body',)
  27. admin.site.register(ArchiveSection, ArchiveSectionAdmin)
  28. admin.site.register(ArchiveStory)
  29. admin.site.register(ArchiveDocument)
  30. admin.site.register(ArchiveMovie)
  31. admin.site.register(ArchiveSlideshow)
  32. class AttachedLinkInline(generic.GenericStackedInline):
  33. extra=1
  34. model=AttachedLink
  35. class AttachedDocumentInline(generic.GenericStackedInline):
  36. extra=1
  37. model=AttachedDocument
  38. class AttachedGraphicInline(generic.GenericStackedInline):
  39. extra=1
  40. model=AttachedGraphic
  41. class AttachedGalleryInline(generic.GenericStackedInline):
  42. extra=1
  43. model=AttachedGallery
  44. class StoryAdmin(admin.ModelAdmin):
  45. save_on_top=True
  46. raw_id_fields = ['lead_photo']
  47. actions_selection_counter = True
  48. inlines = [
  49. AttachedGalleryInline,
  50. AttachedGraphicInline,
  51. AttachedLinkInline,
  52. AttachedDocumentInline,
  53. ]
  54. prepopulated_fields={"slug": ("web_hed",)}
  55. list_display = ('web_hed', 'dateline', 'created', 'published', 'created_by', 'view_count',)
  56. date_hierarchy='published_on'
  57. filter_horizontal=('authors', 'towns', 'sites', 'paper_editions',)
  58. list_filter = ('dateline', 'published', 'sites',)
  59. search_fields = ('web_hed','body','authors__name',)
  60. fieldsets = [
  61. (None, {'fields': [('web_hed','print_hed'),('slug','standing_hed'), ('kicker', 'subhed'),'authors', 'dateline','body', 'markup', 'lead_photo']}),
  62. ('Meta', {'fields': ['summary', ('auto_tag', 'tags')]}),
  63. ('Placement', {'fields': ['weight','paper_editions', 'status', ('published','published_on'),'towns', 'sites']}),
  64. ]
  65. def formfield_for_dbfield(self, db_field, **kwargs):
  66. if db_field.name == 'body':
  67. kwargs['widget'] = AdminMarkItUpWidget()
  68. return super(StoryAdmin, self).formfield_for_dbfield(db_field, **kwargs)
  69. def save_model(self, request, obj, form, change):
  70. if not change:
  71. obj.created_by = request.user
  72. obj.save()
  73. admin.site.register(Story, StoryAdmin)
  74. #class PageAdmin(admin.ModelAdmin):
  75. # save_on_top=True
  76. # search_fields=('ad_notes', 'ad_spec_pos',)
  77. # list_display = ('edition','number','type',)
  78. # list_filter = ('type', 'edition',)
  79. #admin.site.register(Page, PageAdmin)
  80. admin.site.register(Link)
  81. admin.site.register(Paper)
  82. class WebEditionAdmin(admin.ModelAdmin):
  83. raw_id_fields = ['featured_story', 'featured_photo']
  84. filter_horizontal=('stories', 'photos', 'galleries', 'editorials','remembrances','death_announcements','memorial_services','inmemoriams')
  85. fieldsets = [
  86. (None, {'fields': ['paper', ('published', 'published_on'), 'site']}),
  87. ('Editorial', { 'fields': ['featured_story', 'featured_photo', 'stories', 'editorials', 'pdfdocuments']}),
  88. ('Multimedia', {'classes': ['collapse'], 'fields': ['photos', 'galleries', 'movies', 'slideshows']}),
  89. ('Obits', {'classes': ['collapse'], 'fields': ['remembrances', 'death_announcements', 'memorial_services', 'inmemoriams']}),
  90. ]
  91. admin.site.register(WebEdition, WebEditionAdmin)
  92. admin.site.register(PaperEdition)
  93. admin.site.register(AuthorType)
  94. admin.site.register(StandingHed)
  95. #admin.site.register(PageType)