<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/open-iconic/1.1.1/font/css/open-iconic-bootstrap.min.css">
<title>Bootstrap 4</title>
</head>
<body>
<div class="row p-3">
<div class="col-md-6 mb-3">
<label class="sr-only">End Date/Time</label>
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text">Start Date</div>
</div>
<div class="invalid-feedback order-1">
Error Message
</div>
<input type="text" class="form-control is-invalid" placeholder="Date Input">
<div class="input-group-append">
<div class="input-group-text"><i class="oi oi-calendar"></i></div>
</div>
</div>
</div>
</div>
</body>
</html>
你好,我有一个问题。如果我有这样的模型,如何预先将评论显示为线程?
答案 0 :(得分:0)
评论可以有多个子评论,因此这个模型不起作用。将sub_comment
替换为parent = models.ForeignKey(..., related_name='subcomments')
。然后,您可以说comment.subcomments
将为您提供相关的对象管理器,因此comment.subcomments.all()
将是您可以迭代的所有子评论的查询。