【发布时间】:2018-08-03 21:47:13
【问题描述】:
所以我正在加载我的查询集以发送到我的模板。其中一个对象是事故。
现在,每个事件都有一堆属性,比如“状态”和“员工”,所以在我的模板中我可以这样做
// incident.html //
{% for incident in incidents %}
<h1> {{ incident.employee }} - {{ incident.status }} </h1>
{% endfor %}
现在,为方便起见,我想添加事件之前不存在的新属性,例如“情绪”或其他,我可以添加
// views.py //
def get_context_data(self, **kwargs):
...
for incident in incidents:
incident.mood = "scary"
然后在我的模板中,我可以访问 event.mood 以及 event.status 和 event.employee。
// incident.html //
{% for incident in incidents %}
<h1> {{ incident.employee }} - {{ incident.status }} </h1>
<h3> It was very {{ incident.mood }} </h3>
{% endfor %}
所以,我想知道的是,如果我在这里不小心,是否有可能搞砸并破坏性地更改数据库?如果我添加
// views.py //
def get_context_data(self, **kwargs):
...
for incident in incidents:
incident.employee = "Daffy Duck"
我是否会毁掉我的所有数据,并在我的每一次事件中永久地将员工的名字命名为“唐老鸭”?
提前致谢。
【问题讨论】:
标签: django database templates view