Last active
February 28, 2021 03:43
-
-
Save mchesler613/d7a15eab07f15015249bb0298903bb39 to your computer and use it in GitHub Desktop.
Django Models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Person has one-to-one relationship with Email and Bio | |
class Person(models.Model): | |
STATUS = [ | |
('AWAY', 'I am away'), | |
('BUSY', 'I am busy'), | |
('MEETING', 'I am in a meeting'), | |
('IDLE', 'I am available') | |
] | |
name = models.CharField(max_length=20) | |
status = models.CharField(max_length=10, choices=STATUS, default='IDLE') | |
age = models.IntegerField(default=0) | |
... | |
# Bio has a one-to-one relationship with Person, but can be NULL | |
class Bio(models.Model): | |
bio = models.TextField() | |
image = models.URLField() | |
person = models.OneToOneField(Person, on_delete=models.CASCADE) | |
... | |
# Email has one-to-one relationship with Person | |
class Email(models.Model): | |
address = models.EmailField() | |
person = models.OneToOneField(Person, on_delete=models.CASCADE) | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment