我正在使用 Python(3.7) 和 Django(2.1) 开发一个项目,在该项目中我正在更新模型并保存它,之后如果我首先检查列表视图,它会正确显示更新,但是一旦我打开详细视图它丢失了更新并返回到以前的状态。
这是我尝试过的:
来自models.py:
class Order(models.Model):
status_choices = (
('Active', 'Active'),
('Completed', 'Completed'),
('Late', 'Late'),
('Short', 'Short'),
('Canceled', 'Canceled'),
('Submitted', 'Submitted')
)
delivery_status_choices = (
('Accepted', 'Accepted'),
('Rejected', 'Rejected')
)
gig = models.ForeignKey('Gig', on_delete=models.CASCADE)
seller = models.ForeignKey(User, on_delete=models.CASCADE, related_name='selling')
buyer = models.ForeignKey(User, on_delete=models.CASCADE, related_name='buying')
created_at = models.DateTimeField(auto_now=timezone.now())
charge_id = models.CharField(max_length=234)
days = models.IntegerField(blank=False)
status = models.CharField(max_length=255, choices=status_choices)
delivery = models.FileField(upload_to=content_file_name, blank=True)
def __str__(self):
return f'{self.buyer} order from {self.seller}'
来自template.html:
{% if not order.status == 'Completed' and not order.status == 'Submitted' and not order.status == 'Canceled' %}
{% if order.buyer.username == user.username %}
<form method="post" action="{% url 'order-cancel' %}">
{% csrf_token %}
<input type="text" name="id" value="{{ order.id }}" hidden />
<button type="submit" class="btn btn-primary align-content-center">Cancel the Order</button>
</form>
{% elif order.status == 'Canceled' %}
<p> Your order has been canceled already!</p>
{% endif %}
{% else %}
<p> You can't cancel this order now.</p>
{% endif %}
我正在尝试更新statusof order,当我提交order-cancel查看请求时,首先将其另存status为已取消,当我加载detailed(单个对象页面)时,它将更新status后的 o恢复一次。
这里有什么问题?
倚天杖
相关分类