from models import Resource, ResourceCollection, Contact
from django.contrib import admin

class ResourceAdmin(admin.ModelAdmin):
    list_display = ('title', 'couchDB_link', 'edit_metadata_link', 'published')
    filter_horizontal = ['editors', 'collections']
    list_filter = ('published', 'collections')
    search_fields = ['title', 'metadata_id']
    
class ResourceCollectionAdmin(admin.ModelAdmin):
    filter_horizontal = [ 'editors', 'parents' ]
    list_display = ('title', 'collection_id', 'couchDB_link')
    search_fields = ['title', 'collection_id']
    
admin.site.register(Resource, ResourceAdmin)
admin.site.register(ResourceCollection, ResourceCollectionAdmin)
admin.site.register(Contact)

from models import Resource, ResourceCollection, Contact
from django.contrib import admin

def make_published(modeladmin, request, queryset):
    queryset.update(published=True)
make_published.short_description = "Mark selected resources as published"

class ResourceAdmin(admin.ModelAdmin):
    list_display = ('title', 'couchDB_link', 'edit_metadata_link', 'published')
    filter_horizontal = ['editors', 'collections']
    list_filter = ('published', 'collections')
    search_fields = ['title', 'metadata_id']
    actions = [make_published]
    
class ResourceCollectionAdmin(admin.ModelAdmin):
    filter_horizontal = [ 'editors', 'parents' ]
    list_display = ('title', 'collection_id', 'couchDB_link')
    search_fields = ['title', 'collection_id']
    
admin.site.register(Resource, ResourceAdmin)
admin.site.register(ResourceCollection, ResourceCollectionAdmin)
admin.site.register(Contact)

Add bulk updating of a model's published status
Add bulk updating of a model's published status

  from models import Resource, ResourceCollection, Contact
  from django.contrib import admin
+ 
+ def make_published(modeladmin, request, queryset):
+     queryset.update(published=True)
+ make_published.short_description = "Mark selected resources as published"
  
  class ResourceAdmin(admin.ModelAdmin):
      list_display = ('title', 'couchDB_link', 'edit_metadata_link', 'published')
      filter_horizontal = ['editors', 'collections']
      list_filter = ('published', 'collections')
      search_fields = ['title', 'metadata_id']
+     actions = [make_published]
      
  class ResourceCollectionAdmin(admin.ModelAdmin):
      filter_horizontal = [ 'editors', 'parents' ]
      list_display = ('title', 'collection_id', 'couchDB_link')
      search_fields = ['title', 'collection_id']
      
  admin.site.register(Resource, ResourceAdmin)
  admin.site.register(ResourceCollection, ResourceCollectionAdmin)
  admin.site.register(Contact)
  
Add bulk updating of a model's published status
## Code Before:
from models import Resource, ResourceCollection, Contact
from django.contrib import admin

class ResourceAdmin(admin.ModelAdmin):
    list_display = ('title', 'couchDB_link', 'edit_metadata_link', 'published')
    filter_horizontal = ['editors', 'collections']
    list_filter = ('published', 'collections')
    search_fields = ['title', 'metadata_id']
    
class ResourceCollectionAdmin(admin.ModelAdmin):
    filter_horizontal = [ 'editors', 'parents' ]
    list_display = ('title', 'collection_id', 'couchDB_link')
    search_fields = ['title', 'collection_id']
    
admin.site.register(Resource, ResourceAdmin)
admin.site.register(ResourceCollection, ResourceCollectionAdmin)
admin.site.register(Contact)

## Instruction:
Add bulk updating of a model's published status
## Code After:
from models import Resource, ResourceCollection, Contact
from django.contrib import admin

def make_published(modeladmin, request, queryset):
    queryset.update(published=True)
make_published.short_description = "Mark selected resources as published"

class ResourceAdmin(admin.ModelAdmin):
    list_display = ('title', 'couchDB_link', 'edit_metadata_link', 'published')
    filter_horizontal = ['editors', 'collections']
    list_filter = ('published', 'collections')
    search_fields = ['title', 'metadata_id']
    actions = [make_published]
    
class ResourceCollectionAdmin(admin.ModelAdmin):
    filter_horizontal = [ 'editors', 'parents' ]
    list_display = ('title', 'collection_id', 'couchDB_link')
    search_fields = ['title', 'collection_id']
    
admin.site.register(Resource, ResourceAdmin)
admin.site.register(ResourceCollection, ResourceCollectionAdmin)
admin.site.register(Contact)
