小编ant*_*tiu的帖子

来自另一个模型的 Django 外键引用

我有以下型号:

class Author(models.Model):
   name = models.CharField(max_length=255, unique=True)
   """books = Attribute which allows an access to books from this author"""
   class Meta:
      ordering = ['name']


class Book(models.Model):
   name = models.CharField(max_length=255, unique=True)
   author = models.ForeignKey(Author, on_delete=models.CASCADE)
   class Meta:
      ordering = ['name']
Run Code Online (Sandbox Code Playgroud)

如何为 Author 设置一个属性,以便我可以访问其书籍?

django foreign-key-relationship

2
推荐指数
1
解决办法
2878
查看次数

标签 统计

django ×1

foreign-key-relationship ×1