+# -*- coding: utf-8 -*-
+from django.conf.urls import url
from django.contrib import admin
+from django.http.response import HttpResponse
-# Register your models here.
+from newsletter.models import Subscription
+
+
+class SubscriptionAdmin(admin.ModelAdmin):
+ def get_urls(self):
+ urls = super(SubscriptionAdmin, self).get_urls()
+ my_urls = [
+ url(r'^extract/$', self.extract_subscribers, name='extract_subscribers'),
+ ]
+ return my_urls + urls
+
+ def extract_subscribers(self, request):
+ return HttpResponse(',\n'.join(Subscription.objects.values_list('email', flat=True)), content_type='text/plain')
+
+
+admin.site.register(Subscription, SubscriptionAdmin)
class Subscription(Model):
- email = EmailField(verbose_name=_('email address'))
- active = BooleanField(default=True)
+ email = EmailField(verbose_name=_('email address'), unique=True)
+ active = BooleanField(default=True, verbose_name=_(u'active'))
created_at = DateTimeField(auto_now_add=True)
last_modified = DateTimeField(auto_now=True)
+
+ class Meta:
+ verbose_name = _('subscription')
+ verbose_name_plural = _('subscriptions')
+
+ def __unicode__(self):
+ return self.email
\ No newline at end of file