When to use update - Deepstash

When to use update

  • you are updating fields of one or many records (note: update cannot be used to create a new record, like save can).
  • you don't need to re-use a model instance after updating.
  • you don't need your overridden save() method or any pre_save or post_save signals to run.
  • you know what your new field values must be without having retrieved the record(s).

2

14 reads

CURATED FROM

IDEAS CURATED BY

The idea is part of this collection:

Metaverse

Learn more about artificialintelligence with this collection

Find out the challenges it poses

Learn about the potential impact on society

Understanding the concept of Metaverse

Related collections

Similar ideas to When to use update

Save

The ".save()" method is used to write a model instance to the database. It can be an existing record or even a new one. For an existing record, Django will run a SQL UPDATE statement on the database. For a new record, Django will run an INSERT.

Saving with update_fields

To prevent updating every field of the model you can use the update_fields parameter. It expects a list of fields that you want to save. The UPDATE that is run against the database then only updates those fields that you have specified.

For example, in case we only want to update the price ...

Use your to-do list to boost your confidence

To build confidence for the big goals, you first need to focus on the smaller goals - the actions you take every day. What is the one thing you want to do the least? That is often the thing you're unsure about or worried that you might fail at.

Read & Learn

20x Faster

without
deepstash

with
deepstash

with

deepstash

Personalized microlearning

100+ Learning Journeys

Access to 200,000+ ideas

Access to the mobile app

Unlimited idea saving

Unlimited history

Unlimited listening to ideas

Downloading & offline access

Supercharge your mind with one idea per day

Enter your email and spend 1 minute every day to learn something new.

Email

I agree to receive email updates