Ajout de search fields
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / sitotheque / admin.py
CommitLineData
61fb0b58
AJ
1# -*- encoding: utf-8 -*-
2from django.contrib import admin
264a3210
EMS
3from django.core.urlresolvers import reverse as url
4from django.http import HttpResponseRedirect
81fe476e 5from models import Site, SiteVoir
61fb0b58 6
264a3210 7class SiteAdmin(admin.ModelAdmin):
fc2908e4
EMS
8 list_display = ['titre', 'recherche_google']
9 list_editable = ['recherche_google']
a5f76eb4 10 list_filter = ('discipline', 'regions')
befea523
PP
11 search_fields = ('titre', 'description')
12 actions = ('assigner_regions', 'assigner_disciplines')
61fb0b58 13
41d30718
EMS
14 def queryset(self, request):
15 return Site.all_objects.all()
16
264a3210
EMS
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'
61fb0b58 21
264a3210
EMS
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
27admin.site.register(Site, SiteAdmin)
81fe476e
PP
28
29class 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
40admin.site.register(SiteVoir, SiteVoirAdmin)