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 4616230
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:57:09+00:00 2026-05-22T01:57:09+00:00

How would you speed up the Django Admin record deletion action/page? I have a

  • 0

How would you speed up the Django Admin record deletion action/page?

I have a model B with a foreign key constraint to model A. For every record in A, there are about 10k records in B bound to A. So when I have to delete a record in A using the default “Delete selected A” action in admin, Django will take 15 minutes to query and display every record being deleted in B. How would I modify this so instead of listing thousands of dependent objects, it only displays a count of the dependent objects being deleted?

  • 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-05-22T01:57:09+00:00Added an answer on May 22, 2026 at 1:57 am

    As usual browse the django source to find your answer (it’s surprisingly readable with variables, functions, classes, and files named logically).

    Looking at django/contrib/admin/templates/admin/delete_confirmation.html (in django 1.2.5), you will see a template that has the 24th line contains:

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

    If you change this to say

    <p>{{ deleted_objects|count }} objects</p>
    

    or

    {% if 100 < deleted_objects|count %}
        <p>{{ deleted_objects|count }} objects</p>
    {% else %}
        <ul>{{ deleted_objects|unordered_list }}</ul>
    {% endif %}
    

    it will only display the count of deleted objects (if there are many deleted objects).

    You may also want to experiment with editing django/contrib/admin/templates/admin/actions.py to use a SQL transaction to do the mass deletion more quickly. See: http://docs.djangoproject.com/en/dev/topics/db/transactions/

    Basically action.py currently works by forming the appropriate queryset, calling delete() directly the queryset, but not grouping it into a single db transaction. Doing simple time tests on a sample sqlite database I found that deleting ~150 objects without transactions took 11.3 seconds using qs.delete() and 13.4 seconds using for obj in qs: obj.delete(). Using transactions (@transaction.commit_on_success before the deleting functions), the same commands took only 0.35 seconds and 0.39 seconds (about 30 times faster). Granted using transactions may lock the database temporarily, which may not be an acceptable option.

    To extend the django admin sensibly (normally you wouldn’t want to edit the source directly; especially if other users are using the same files or if you may ever want to revert back later or are running other django sites on the same machine) see:
    http://www.djangobook.com/en/1.0/chapter17/#cn35

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would there be difference in speed between if (myInt == CONST_STATE1) and if (myEnum
I would like to know if there is a difference in speed between computing
I would like to add a typing speed indicator just below the textarea we
How would you make the folowing code functional with the same speed? In general,
I am just coming up to speed on WPF and would like to create
Using groovy, would you expect better performance in terms of speed and memory overhead
Is there a way to speed up PostgreSQL's createdb command? Normally I wouldn't care,
I was wondering if adding a LIMIT 1 to a query would speed up
I have a Django management command that makes thousands of TCP/UDP requests. I've used
I'm wondering if using by AsParallel would speed up my code in the way

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.