Create if does not exist

I have a Django application that reads data from a web API and puts it in a database.
Is there a way to create a new object from mode, but prevent a duplicate exception if the object already exists?

In other words, is there a way to save the object, but just do nothing if it already exists?

+45
django models
Jan 07 2018-12-12T00:
source share
2 answers
+82
Jan 7 2018-12-12T00:
source share

In Django 1.7, you can also:

Model.objects.update_or_create()

+35
Sep 06 '13 at 7:58
source share



All Articles