📜  如何在 jdango 的模型中连接 id - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:31.874000             🧑  作者: Mango

代码示例3
from django.db import models

class Musician(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    instrument = models.CharField(max_length=100)

class Album(models.Model):
    artist = models.ForeignKey(Musician, on_delete=models.CASCADE)
    name = models.CharField(max_length=100)
    release_date = models.DateField()
    num_stars = models.IntegerField()