Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7830727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:23:02+00:00 2026-06-02T11:23:02+00:00

I added an admin action send_EMAIL through admin.py . When admin uses the send_EMAIL

  • 0

I added an admin action send_EMAIL through admin.py. When admin uses the send_EMAIL action for selected users I want it to show an intermediate page with all selected users and ask for confirmation. In my case, it asks for confirmation but when I click on the "send Email" button nothing happens, and I get returned to the change_list view without the send_EMAIL action getting called.

Admin.py

class MyUserAdmin(UserAdmin):
    list_display = ['username', 'email', 'first_name', 'last_name', 'is_active', staff]
    list_filter = ['groups', 'is_staff', 'is_superuser', 'is_active']
    actions = ['send_EMAIL']

    
    def send_EMAIL(self, request, queryset):
        from django.core.mail import send_mail
        if 'apply' in request.POST:
            for i in queryset:
                if i.email:
                    send_mail('Subject here', 'Here is the message.', 'from@example.com',[i.email], fail_silently=False)
                else:
            self.message_user(request, "Mail sent successfully ")
        else:
            from django.http import HttpResponse
            from django.template import RequestContext, loader
            t = loader.get_template('admin/send_mail.html')
            c = RequestContext(request, {'articles': queryset})
            return HttpResponse(t.render(c),)
            
    
    
admin.site.unregister(User)
admin.site.register(User, MyUserAdmin)

templates/send_mail.html

{% extends "admin/base_site.html" %}

{% block content %}


<form action="" method="post">{% csrf_token %}

    <p>The mail will be send to following users:</p>

    <ul>{{ articles|unordered_list }}</ul>

    <input type="hidden" name="action" value="send_EMAIL" />
    <input type="submit" name="apply" value="Send Email" />
</form>

{% endblock %} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T11:23:04+00:00Added an answer on June 2, 2026 at 11:23 am

    I found an easy way to do it. It worked for me… I hope it helps:

    What you need to do is to “pass” the selected items to the confirmation page and include them in the form as well as including the <input type="hidden" name="action" value="admin_action" /> so that django admin knows that it should still call an admin action. The post is just to know whether to process the query set or render the confirmation page.

    # Write your admin action.
    # IMPORTANT: Note the context passed to TemplateResponse
    
    from django.contrib.admin import helpers
    from django.template.response import TemplateResponse
    
    class MyModelAdmin(admin.ModelAdmin):
        def admin_action(self, request, queryset):
            if request.POST.get('post'):
                # process the queryset here
            else:
                context = {
                    'title': _("Are you sure?"),
                    'queryset': queryset,
                    'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME,
                }
                return TemplateResponse(request, 'path/to/template.html',
                    context, current_app=self.admin_site.name)
    
    # The template
    {% extends "admin/base_site.html" %}
    {% load i18n l10n %}
    
    {% block content %}
    <form action="" method="post">{% csrf_token %}
        <p>The following videos will be accepted:</p>
    
        <ul>{{ queryset|unordered_list }}</ul>
    
        <div>
        {% for obj in queryset %}
        <input type="hidden" name="{{ action_checkbox_name }}" value="{{ obj.pk|unlocalize }}" />
        {% endfor %}
        <input type="hidden" name="action" value="admin_action" />
        <input type="hidden" name="post" value="yes" />
        <input type="submit" value="{% trans "Yes, I'm sure" %}" />
        </div>
    </form>
    {% endblock %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a Django Admin Action that allows me to create a
UPDATED: Added one more question (Question #4). Hi all, I'm building myself a custom
I added a batch (.bat) file to my project. I want to add a
I am using rails 3.2 and devise 1.5.3. I added an admin attribute in
I have created a module called Admin and created a controller Admin through zend
I want to update a page when my database is modified. I want to
I am designing an admin interface where invite mails will be sent to users.
in /admin/sales_order/view/ I want to add a link on the left menu where I
I have added the Authentication attribute on controller classes which are for admin purposes
I just added active admin to my rails app and I'm unable to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.