Answers for "django on_delete rules"

0

django on_delete rules

from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models

def get_sentinel_user():
    return get_user_model().objects.get_or_create(username='deleted')[0]

class MyModel(models.Model):
    user = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.SET(get_sentinel_user),
    )
Posted by: Guest on August-19-2021

Python Answers by Framework

Browse Popular Code Answers by Language