I know in django we can create an object model easily by using something like this
AbcModel.objects.create(field1='a', field2='b')
But this would create the object even if it already exists.
I know I can use filter()
then use the exist()
to check if the object already exist then decide to update or create.
But is there an easier and faster way to do this? Since, there is get_or_create
so I am curious if there's something similar.
Thanks in advance
EDIT: I thought of something like this
new = AbcModel.objects.create(field1='a')
new[0].field2 = 'c'
new[0].save()
There might be more fields and field1
will not always be a
would be others like b
, c
and maybe a
again.
Just being curious if there is an easier faster way and not saying get_or_create
wouldn't get what I want / need