Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Dmitry Mugtasimov
    I do understand, does Django 1.8 save only changed fields by default or all fields?
    Saving Data¶§
    Starting in Django 1.5, calling .save() only updates the fields that have changed.
    Prior to 1.5, .save() updated the entire model, making it easy to overwrite changes
    django-dirtyfields lets you track which fields have been changed if you’re stuck on an older version of Django (but does not change .save() behavior on its own)
    Romain Garrigues
    Hi @dmugtasimov !
    Sorry for the delay, nobody used this gitter before you
    what is written is wrong for me
    what has changed related to save() before and after Django 1.5 is the way Django is querying the DB (in Django 1.5 and earlier, Django did a SELECT when the primary key attribute was set. If the SELECT found a row, then Django did an UPDATE, otherwise it did an INSERT. The old algorithm results in one more query in the UPDATE case.)
    Just to be sure about that, let's see this in Django 1.8 documentation:

    Specifying which fields to save¶

    If save() is passed a list of field names in keyword argument update_fields, only the fields named in that list will be updated. This may be desirable if you want to update just one or a few fields on an object. There will be a slight performance benefit from preventing all of the model fields from being updated in the database

    Romain Garrigues
    And that's what is used in django-dirtyfields: save(update_fields=['field1', 'field2' ])
    Romain Garrigues
    I have proposed to fix that documentation on github and my MR has been merged nyergler/effective-django#14.