FAQ
I'm working on a simple mailing list app using Django 1.5

my admin.py looks like this:

from django.contrib import admin
from mailing_list.models import MailingList
from django.core.mail import send_mail
from django import forms
from django.shortcuts import render
from django.http import HttpResponseRedirect

class MailingListAdmin(admin.ModelAdmin):
     list_display = ('name', 'email', 'shows', 'music', 'merchandise',
'news', 'blog')
     list_filter = ('shows', 'music', 'merchandise', 'news', 'blog')

     actions = ['new_message']

     class SendMailForm(forms.Form):
         _selected_action = forms.CharField(widget=forms.MultipleHiddenInput)
         subject = forms.CharField(max_length=250)
         message = forms.CharField(widget=forms.Textarea(attrs={"rows": 10,
"cols": 30}))

     def new_message(self, request, queryset):
         form = None

         if 'apply' in request.POST:
             form = self.SendMailForm(request.POST)

             if form.is_valid():
                 subject = form.cleaned_data['subject']
                 message = form.cleaned_data['message']
                 recipients = []

                 for person in queryset:
                     recipients.append(person.email)

                 send_mail(subject, message, "info@website.com", recipients,
fail_silently=False)

                 number = len(recipients)
                 self.message_user(request, "Successfully sent email to %d
recipients" % number)
                 return HttpResponseRedirect(request.get_full_path())

         else:
             form = self.SendMailForm(initial={'_selected_action':
request.POST.getlist(admin.ACTION_CHECKBOX_NAME)})

         return render(request, 'admin/send_mail.html', {'emails': queryset,
'mail_form':form})

     new_message.short_description = "Send Mail"

admin.site.register(MailingList, MailingListAdmin)

It doesn't kick any errors however, the mail isn't sent and I don't get the
message_user. It just sends me back to the original admin page and displays
"No Action Selected". I've probably been spinning my tires too much on this
and it's likely something stupid but I'm frustrated and out of ideas.
Any help would be appreciated.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/482e9534-8aee-4f52-8c1e-e6f268131d7e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdjango-users @
categoriesdjango, python
postedOct 21, '13 at 9:56p
activeOct 21, '13 at 9:56p
posts1
users1
websitedjangoproject.com

1 user in discussion

Daniel Worth: 1 post

People

Translate

site design / logo © 2022 Grokbase