From 6c0728cc000117f121ac9fdc70cd62ba500c2cf7 Mon Sep 17 00:00:00 2001 From: Stephen Burrows Date: Thu, 24 Feb 2011 12:20:19 -0500 Subject: [PATCH] Added an admin action to NewsletterArticleAdmin to handle creating a NewsletterIssue from a selection of articles. Resolves issue 82. --- contrib/penfield/admin.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/contrib/penfield/admin.py b/contrib/penfield/admin.py index 950539d..328394a 100644 --- a/contrib/penfield/admin.py +++ b/contrib/penfield/admin.py @@ -1,5 +1,7 @@ -from django.contrib import admin from django import forms +from django.contrib import admin +from django.core.urlresolvers import reverse +from django.http import HttpResponseRedirect, QueryDict from philo.admin import EntityAdmin, AddTagAdmin, COLLAPSE_CLASSES from philo.contrib.penfield.models import BlogEntry, Blog, BlogView, Newsletter, NewsletterArticle, NewsletterIssue, NewsletterView @@ -91,10 +93,18 @@ class NewsletterArticleAdmin(TitledAdmin, AddTagAdmin): 'classes': COLLAPSE_CLASSES }) ) + actions = ['make_issue'] def author_names(self, obj): return ', '.join([author.get_full_name() for author in obj.authors.all()]) author_names.short_description = "Authors" + + def make_issue(self, request, queryset): + opts = NewsletterIssue._meta + info = opts.app_label, opts.module_name + url = reverse("admin:%s_%s_add" % info) + return HttpResponseRedirect("%s?articles=%s" % (url, ",".join([str(a.pk) for a in queryset]))) + make_issue.short_description = u"Create issue from selected %(verbose_name_plural)s" class NewsletterIssueAdmin(TitledAdmin): -- 2.20.1