I have the code below:
# "store/models.py"
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=30)
# "store/admin.py"
from django.contrib import admin
from .models import Person
@admin.register(Person)
class PersonAdmin(admin.ModelAdmin):
pass
Then, when changing data as shown below:
SELECT
is run instead of SELECT FOR UPDATE
as shown below. *I use PostgreSQL and these logs below are the queries of PostgreSQL and you can check On PostgreSQL, how to log queries with transaction queries such as "BEGIN" and "COMMIT":
And, when clicking Delete
button of Change person as shown below:
Then clicking Yes, I'm sure
button to delete data as shown below:
SELECT
is run instead of SELECT FOR UPDATE
as shown below:
Now, I want to run SELECT FOR UPDATE
instead of SELECT
for both cases as shown above.
So, how can I do this?
You need to override get_queryset() with select_for_update() as shown below:
Then, when changing data as shown below:
SELECT FOR UPDATE
is run instead ofSELECT
as shown below:And, when clicking
Delete
button of Change person as shown below:Then clicking
Yes, I'm sure
button to delete data as shown below:SELECT FOR UPDATE
is run instead ofSELECT
as shown below: