たとえばArticleが複数のCommentを持つ場合
Rails の場合
article.comments
djangoの場合
article.comment_set.all()
モデル定義の例
Railsだと
- 親クラスに has_many 関連を書く
- 子クラスに belongs_to 関連を書く
というやり方だが、 djangoだと子クラスにだけ関連を記述すれば良いようだ
class Article(models.Model):
...
class Comment(models.Model):
article = models.ForeignKey(Article, on_delete=models.CASCADE)
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。