Skip to content

Instantly share code, notes, and snippets.

@i
Created July 19, 2018 15:21
Show Gist options
  • Save i/84c942c650fa38fcecccf25f27355f57 to your computer and use it in GitHub Desktop.
Save i/84c942c650fa38fcecccf25f27355f57 to your computer and use it in GitHub Desktop.
class Car(models.Model):
# CASCADE is the default behavior. When this car's manufacturer is deleted,
# this car will also be deleted
manufacturer = models.ForeignKey(Manufacturer, on_delete=models.CASCADE)
# SET_NULL makes it so when this car's owner gets deleted, it will continue
# to exist without an owner.
owner = models.ForeignKey(User, on_delete=models.SET_NULL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment