我正在使用Django 1.6,但这个错误存在于1.5。
我有自己的用户类,没有用户名字段,只有电子邮件。
在我的settings.py中,我更新了AUTH_USER_MODEL,当我想在Django管理站点中验证或编辑现有用户时,一切正常。
但是当我想添加新的,而不是现有的用户时,我有以下错误:
TypeError at /admin/users/account/add/
'int' object is not iterable
Request Method: GET
Request URL: http://localhost:8000/admin/users/account/add/
Django Version: 1.6
Exception Type: TypeError
Exception Value:
'int' object is not iterable
Exception Location: /home/kaczor/git/panzer4/env/local/lib/python2.7/site-packages/django/forms/widgets.py in render_options, line 526
...
In template /home/kaczor/git/panzer4/env/local/lib/python2.7/site-packages/django/contrib/admin/templates/admin/includes/fieldset.html, error at line 19
'int' object is not iterable
9 {% for field in line %}
10 <div{% if not line.fields|length_is:'1' %} class="field-box{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}>
11 {% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %}
12 {% if field.is_checkbox %}
13 {{ field.field }}{{ field.label_tag }}
14 {% else %}
15 {{ field.label_tag }}
16 {% if field.is_readonly %}
17 <p>{{ field.contents|linebreaksbr }}</p>
18 {% else %}
**19 {{ field.field }}**
20 {% endif %}
21 {% endif %}
22 {% if field.field.help_text %}
23 <p class="help">{{ field.field.help_text|safe }}</p>
24 {% endif %}
25 </div>
26 {% endfor %}
27 </div>
28 {% endfor %}
29 </fieldset>
我的模型看起来像:
class Account(AbstractBaseUser, PermissionsMixin):
email = models.CharField(max_length=40, unique=True, blank=False, db_index=True)
first_name = models.CharField(max_length=64, null=True)
last_name = models.CharField(max_length=64, null=True)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
categories_allowed = TreeManyToManyField(Category, default=1)
objects = AccountManager()
def save(self, *args, **kwargs):
if not self.email or self.email == '':
raise ValueError(NO_EMAIL_ERROR)
else:
super(Account, self).save(*args, **kwargs)
def __unicode__(self):
return "%s %s" % (self.first_name, self.last_name)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
Django Admin允许编辑用户,但是当我点击添加按钮时失败。 这有什么问题?