comparison email_list/admin.py @ 71:e2868ad47a1e

For Django 1.4, using the new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 14 Apr 2012 16:40:29 -0500
parents madeira/email_list/admin.py@9b9daefba97a
children 312f198e8958
comparison
equal deleted inserted replaced
70:f26cdda0ad8b 71:e2868ad47a1e
1 """
2 Automatic admin definitions for the email_list application.
3
4 """
5 from django.contrib import admin
6 from django.conf.urls import patterns, url
7 from django.shortcuts import render, redirect
8
9 from email_list.models import Subscriber
10 from email_list.forms import AdminEmailForm
11
12
13 class SubscriberAdmin(admin.ModelAdmin):
14 list_display = ['__unicode__', 'location', 'status']
15 list_filter = ['status']
16 search_fields = ['name', 'email']
17
18 def get_urls(self):
19 urls = super(SubscriberAdmin, self).get_urls()
20 my_urls = patterns('',
21 url(r'^send_mail/$',
22 self.admin_site.admin_view(self.send_mail),
23 name='email_list-admin_mail'),
24 )
25 return my_urls + urls
26
27 def send_mail(self, request):
28 if request.method == 'POST':
29 form = AdminEmailForm(request.POST)
30 if form.is_valid():
31 n = form.save()
32 msg = '%d mailing list emails sent' % n
33 self.message_user(request, msg)
34 return redirect('admin:index')
35 else:
36 form = AdminEmailForm()
37
38 return render(request, 'email_list/admin_mail.html', {'form': form})
39
40
41 admin.site.register(Subscriber, SubscriberAdmin)