1👍
✅
The Unique error is most likely because the update_or_create
is just trying to create and then getting conflicting primary keys.
Because you are already getting Model1 here: model1 = get_object_or_404(Model1, pk=pk)
you could just replace the update_or_create
with:
model1.status = 'closed'
model1.save()
Note: I didn’t originally post this as an answer because I wasn’t sure if update_or_create
was mandatory or not.
Source:stackexchange.com