0

Sorry if the title of this question sucks but I couldn't find much info on this particular problem. In the docs, the code below is given:

from django.db import models
from django.contrib.auth.models import User

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

class MyModel(models.Model):
    user = models.ForeignKey(User, on_delete=models.SET(get_sentinel_user))

In such a scenario, is there any way by which I can make MyModel delete itself depending on the return value of get_sentinel_user?

ppsreejith
  • 3,318
  • 2
  • 25
  • 27
  • See http://stackoverflow.com/questions/2475249/what-are-the-options-for-overriding-djangos-cascading-delete-behaviour – Paul Draper Oct 28 '13 at 02:20

1 Answers1

0

If I understand your question correctly, you are trying to delete an instantiated class object from within the class itself. I do not believe this is possible. Is it possible to do this check before creating MyModel?

sdamashek
  • 636
  • 1
  • 4
  • 13