Django model method - create_or_update

snakesNbronies picture snakesNbronies · May 2, 2013 · Viewed 38.4k times · Source

Similar to get_or_create, I would like to be able to update_or_create in Django.

Until now, I have using an approaching similar to how @Daniel Roseman does it here. However, I'd like to do this more succinctly as a model method.

This snippet is quite old and I was wondering if there is a better way to do this in more recent version of Django.

Answer

dbkaplun picture dbkaplun · Aug 19, 2013

See QuerySet.update_or_create (new in Django 1.7dev)