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

  • Home
  • SEARCH
  • 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 731439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:01:35+00:00 2026-05-14T07:01:35+00:00

I get a model object, change an attribute, save it and it still has

  • 0

I get a model object, change an attribute, save it and it still has the old attribute:

>>> g = SiteProfile.objects.get(pk=3)
>>> g.renew_date
datetime.date(2010, 4, 11)
>>> g.renew_date = date.today()+timedelta(days=365)
>>> g.renew_date
datetime.date(2011, 4, 11)
>>> g.save()
>>> g.renew_date
datetime.datetime(2010, 4, 11, 16, 57, 4, 192684)

Anyone know if this is an issue with the database or something else?

  • 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-14T07:01:35+00:00Added an answer on May 14, 2026 at 7:01 am

    I figured it out.

    The issue was that the field renew_date had the argument auto_now set to True as such:

    renew_date = models.DateField(auto_now=True, editable=False)
    

    I understood auto_now to mean that the current date will be used when creating the object, but it turns out that’s not the case:

    DateField.auto_now

    Automatically set
    the field to now every time the object
    is saved. Useful for “last-modified”
    timestamps. Note that the current date
    is always used; it’s not just a
    default value that you can override.

    From django docs.

    What I needed was auto_now_add which:

    Automatically set the field to now
    when the object is first created.
    Useful for creation of timestamps.
    Note that the current date is always
    used; it’s not just a default value
    that you can override.

    So, after changing my renew_date field:

    renew_date = models.DateField(auto_now_add=True, editable=False)
    

    it all works, just fine 🙂

    >>> g = SelectStatProfile.objects.get(pk=3)
    >>> g.renew_date
    datetime.date(2010, 4, 11)
    >>> from datetime import date, timedelta
    >>> g.renew_date = date.today()+timedelta(days=365)
    >>> g.renew_date
    datetime.date(2011, 4, 11)
    >>> g.save()
    >>> g.renew_date
    datetime.date(2011, 4, 11)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have Model.objects.all() I want to get only one object for any content_object=foo,
'WSGIRequest' object has no attribute 'username' This is the error I get . I
I have a CoreData model with 2 objects. The first object (Images) contains a
When you decorate a model object's property with the Required attribute and don't specify
from django.contrib.auth.models import User u = User.objects.get(username='test') user.password u'sha1$c6755$66fc32b05c2be8acc9f75eac3d87d3a88f513802 Is reversing this password encryption
Following works fine in shell: >>> from django.contrib.auth.models import User >>> user=User.objects.get(pk=1) >>> user.first_name
How to get model instances of Filter given they should be m2m related to
public AbstractImagePrototype getIcon(ModelData model) { if (model.get(icon) != null) { return Resources.ICONS.lock(); } else
We are trying to get the Model-View-Presenter pattern used on (virtually) all new dev
I'm wondering is there a difference in terms of computing cost for the Model.get(keys)

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.