1
class Post(models.Model):
    ref_no = models.CharField(max_length=6, null=True, blank=True, unique=True)
    select_section = models.CharField(max_length=20, choices=Sections)
    incident = models.TextField(max_length=500, help_text="Mention the incident in brief here.")
    severity = models.CharField(max_length=20, choices=Severity)
    date_posted = models.DateField(auto_now_add=True, auto_now=False, blank=True)
    confirm_closing = models.BooleanField(default=False, help_text="Please confirm to close the Ticket")
    comment = models.TextField(max_length=500, default="Issue resolved and this Ticket has been closed successfully!")
    date_closed = models.DateField(null=True, blank=False, auto_now_add=False, auto_now=False)
    username = models.ForeignKey(User, on_delete=models.CASCADE)

这是我的模型在这里我希望我的 min_date for date_closed字段应该大于我的模型的date_posted字段......请让我知道该怎么做......提前谢谢

4

1 回答 1

0

我建议做这样的事情:

$(document).ready(function () {
    $(".date_picker").datepicker({
        autoclose: true,        
    }).on('change', function () {
        $('.date_closed').datepicker('option', 'minDate', new Date($(".date_posted").val()));
    });
});
input{
margin:10px;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div>
    <label >Posted date:</label>
    <input type="text" name="date_posted" class="form-control date_posted date_picker">
</div>
<div>
    <label >Closed date:</label>
    <input type="text" name="date_closed" class="form-control date_closed date_picker">
</div>

这里我们设置minDate何时更改日期选择器。

于 2020-09-01T14:32:10.600 回答