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
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?
CodePudding user response:
SELECT FOR UPDATE
is run instead of SELECT
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 of SELECT
as shown below:
CodePudding user response:
To run a SELECT FOR UPDATE query instead of a regular SELECT query in Django Admin, you can use the select_for_update() method on your queryset. This method will lock the rows in the queryset until the transaction is committed or rolled back, preventing other transactions from modifying the data in those rows.