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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:27:41+00:00 2026-05-23T09:27:41+00:00

I have a Django model that holds settings core to the function of an

  • 0

I have a Django model that holds settings core to the function of an app. You should never delete this model. I’m trying to enforce this application-wide. I’ve disabled the delete function in the admin, and also disabled the delete method on the model, but QuerySet has it’s own delete method. Example:

MyModel.objects.all()[0].delete() # Overridden, does nothing

MyModel.objects.all().delete() # POOF!

Ironically, the Django docs say has this to say about why delete() is a method on QuerySet and not Manager:

This is a safety mechanism to prevent you from accidentally requesting Entry.objects.delete(), and deleting all the entries.

How having to include .all() is a “safety mechanism” is questionable to say the least. Instead, this effectively creates a backdoor that can’t be closed by conventional means (overriding the manager).

Anyone have a clue how to override this method on something as core as QuerySet without monkey-patching the source?

  • 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-23T09:27:41+00:00Added an answer on May 23, 2026 at 9:27 am

    You can override a Manager's default QuerySet by overriding the Manager.get_query_set() method.

    Example:

    class MyQuerySet(models.query.QuerySet):
    
        def delete(self):
            pass  # you can throw an exception
    
    
    class NoDeleteManager(models.Manager):
        def get_query_set(self):
            return MyQuerySet(self.model, using=self._db)
    
    class MyModel(models.Model)
        field1 = ..
        field2 = ..
    
    
        objects = NoDeleteManager()
    

    Now, MyModel.objects.all().delete() will do nothing.

    For more informations: Modifying initial Manager QuerySets

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

Sidebar

Related Questions

Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
I have Django model that looks like this: class Categories(models.Model): Model for storing the
I have a django model and model form that look like this: -models.py class
I have a Django app with a model that contains a field of type
I have a Django model that holds to-dos with an estimate of the amount
I have a Django Model that implements a time range, like this: class Period(models.Model):
I have a Django model that looks like this. class Solution(models.Model): ''' Represents a
Say I have django model that looks something like this: class Order(models.Model): number =
I'm using django/apache/sqlite3 and I have a django model that looks like this: class
I have a Django model that looks something like this: class Person(models.Model): name =

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.