class MyModel(PostgresModel):
myfield = models.CharField(max_length=255)
obj1 = (
MyModel.objects
.on_conflict(['pk'], ConflictAction.UPDATE)
.insert_and_get(pk=0, myfield='beer')
)
obj2 = (
MyModel.objects
.on_conflict(['pk'], ConflictAction.UPDATE)
.insert_and_get(pk=0, myfield='beer')
)
assert obj1.id == obj2.id
The following example does not work. This is because pk refers to the a models.AutoField, which django-postgres-extra does special logic for. However, it should be possible to override the default value. In the example above, you should end up with 1 row with id=0. However, instead, you end up with to rows with id=1 and id=2.
This is closely related to #23.