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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:59:40+00:00 2026-05-20T04:59:40+00:00

I need to detect when some of the fields of certain model have changed

  • 0

I need to detect when some of the fields of certain model have changed in the admin, to later send notifications depending on which fields changed and previous/current values of those fields.

I tried using a ModelForm and overriding the save() method, but the form’s self.cleaned_data and seld.instance already have the new values of the fields.

  • 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-20T04:59:41+00:00Added an answer on May 20, 2026 at 4:59 am

    Modifying the answer above… taking the brilliant function from Dominik Szopa and changing it will solve your relationship change detection: Use this:

    def get_changes_between_models(model1, model2, excludes = []):
        changes = {}
        for field in model1._meta.fields:
            if not (field.name in excludes):
                if field.value_from_object(model1) != field.value_from_object(model2):
                    changes[field.verbose_name] = (field.value_from_object(model1),
                                                       field.value_from_object(model2))
        return changes
    

    Then in your code you can say (avoid try/except for performance reasons):

    if (self.id):
        old = MyModel.Objects.get(pk=self.id)
        changes = get_changes_between_models(self, old)
    
        if (changes):
            # Process based on what is changed.
    

    If you are doing this at the “model” level, there is no way to save the extra query. The data has already been changed by the time you reach the “Save” point. My first post, so forgive me if I sound like an idiot.

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

Sidebar

Related Questions

i need to detect the strength of the shake. I have to move some
My problem is the following: I have an image in which I detect some
I need to run some code, for example, to detect browser prefered languages and
I need to detect IE7 (and IE6) using the user agent string: I have
I need to detect which version of SQL I am dealing with to perorm
I have some code which reads a file through a form field of type
I need to detect page to do some styling on a website, right now
I need to detect if text input was processed by keyboard or some auto
I have a series of data and need to detect peak values in the
I currently have a like button on my app and I need to detect

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.