Skip to content

Instantly share code, notes, and snippets.

@fodra
Created April 18, 2018 01:21
Show Gist options
  • Save fodra/ae6241f8ed737d4ae54fb486cd3427ca to your computer and use it in GitHub Desktop.
Save fodra/ae6241f8ed737d4ae54fb486cd3427ca to your computer and use it in GitHub Desktop.
Django Relationship notes.
  1. One-to-Many or Many-to-One relationships
  • One gets no field
  • Many gets the ForeignKey field
class One(models.Model):
  pass
  
class Many(models.Model):
  one = models.ForeignKey(One, on_delete=models.XXXXXX)
  
where XXXX can be
CASCADE
SET_NULL
SET_DEFAULT
PROTECT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment