๐ฑ one-to-many
class UserModel(AbstractUser):
class Meta:
db_table = "my_user"
bio = models.TextField(max_length=500, blank=True)
class TweetModel(models.Model):
class Meta:
db_table = "tweet"
author = models.ForeignKey(UserModel, on_delete=models.CASCADE)
content = models.CharField(max_length=256)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class TweetComment(models.Model):
class Meta:
db_table = "comment"
tweet = models.ForeignKey(TweetModel, on_delete=models.CASCADE)
author = models.ForeignKey(UserModel, on_delete=models.CASCADE)
comment = models.CharField(max_length=256)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
๐ฑ one-to-one
class UserModel(AbstractUser):
...(์๋ต)
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
user_pk = models.IntegerField(blank=True)
nickname = models.CharField(max_length=200, blank=True)
point = models.IntegerField(default=0)
phone = models.CharField(max_length=200, blank=True)
๐ฑ many-to-many
class MyTopping(models.Model):
topping_name = models.CharField(max_length=100)
class MyPizza(models.Model):
pizza_name = models.CharField(max_length=100)
pizza_topping = models.ManyToManyField(MyTopping)
๋ฐ์ํ
'STUDY > Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ข Turtle Django | ์ ๋ ์ถ์ฒ + ๋ฆฌ๋ทฐ์๋น์ค (0) | 2022.06.06 |
---|---|
โฑ ํ์์ดํ | ์นดํ ๊ณ ๋ฆฌ ๋ณ๋ก ๊ธ์ ๋ณผ ์ ์๋ ๋ธ๋ก๊ทธ ๋ง๋ค์ด๋ณด๊ธฐ | 5์31์ผ (0) | 2022.06.01 |
django ๋ชจ๋ธ ํ๋์ ์ข ๋ฅ (๊ต์ฅํ ๋ง์ ์ข ๋ฅ๊ฐ ์์ง๋ง,,) (0) | 2022.05.28 |
Django์์ ์ฐ๋ ForeignKey, VSC SQLite์์๋ ๋ชป ๋ณด๋์? ๐ค (0) | 2022.05.28 |
Django | Web framework (0) | 2022.05.28 |