0
我有一個表格,我可以將標題保存爲空,在這種情況下,該函數將空白轉換爲未命名的主鍵。但在我的情況下,保存空白爲空。我不知道是什麼問題。未命名的標題顯示爲空
模板:
<div class="page-header">
<h1>Backtesting{% if form.instance.pk %}: {{form.instance.title}} {% endif %}</div>
<div id="tab1" class="tab" >
<form action="{% url "backtest" %}" method='POST' role='form' id='form'>
{% csrf_token %}
<input type="hidden" name="tabs" value="first" id="toggle-tab1" checked="checked" />
{% include 'tags/parameters_form.html' %}
<br />
{% include 'tags/parameters_backtest_form.html' %}
<br />
{% if user.is_authenticated %}
<input type='submit' id='run' value='Run' class='btn btn-default'>
{% if user.profile.is_active %}
Name: {{ form.title }} <input type='submit' name='save' value='Save' class='btn btn-default'>
{% else %}
<p>
Expired account! you need to reactivate in order to save parameters.
</p>
{% endif %}
{% else %}
Please <a href="{% url 'auth_login' %}">login</a> in order to Run backtesting!
</br>
Our system needs your email in order to notify you once one or more of your simulations are done. This is a safer way for you to keep track of your previous simulations (/jobs).
{% endif %}
的models.py:
title = models.CharField('title', max_length=100, default='', blank=True, help_text='Use an indicative name, related to the chosen parameters')
def __unicode__(self):
if self.title:
return u'%s' % (self.title)
else:
return u'Unnamed%s' % (self.pk)