Ajout de search fields
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / sitotheque / admin.py
1 # -*- encoding: utf-8 -*-
2 from django.contrib import admin
3 from django.core.urlresolvers import reverse as url
4 from django.http import HttpResponseRedirect
5 from models import Site, SiteVoir
6
7 class SiteAdmin(admin.ModelAdmin):
8 list_display = ['titre', 'recherche_google']
9 list_editable = ['recherche_google']
10 list_filter = ('discipline', 'regions')
11 search_fields = ('titre', 'description')
12 actions = ('assigner_regions', 'assigner_disciplines')
13
14 def queryset(self, request):
15 return Site.all_objects.all()
16
17 def assigner_regions(self, request, queryset):
18 selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
19 return HttpResponseRedirect(url('assigner_regions', kwargs=dict(app_name='sitotheque', model_name='site')) + '?ids=' + ','.join(selected))
20 assigner_regions.short_description = u'Assigner des régions'
21
22 def assigner_disciplines(self, request, queryset):
23 selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
24 return HttpResponseRedirect(url('assigner_disciplines', kwargs=dict(app_name='sitotheque', model_name='site')) + '?ids=' + ','.join(selected))
25 assigner_disciplines.short_description = u'Assigner des disciplines'
26
27 admin.site.register(Site, SiteAdmin)
28
29 class SiteVoirAdmin(SiteAdmin):
30
31 actions = None
32 list_editable = []
33
34 def __init__(self, model, admin_site):
35 super(SiteAdmin, self).__init__(model, admin_site)
36
37 self.readonly_fields = self.fields
38
39
40 admin.site.register(SiteVoir, SiteVoirAdmin)