2

I'm using Django 1.6, but this error existed in 1.5.

I have my own user class, which has no username field, only email.

In my settings.py I have AUTH_USER_MODEL updated, everything works fine, when I want to authenticate or i.e. edit existing user in Django Admin site.

But when I want to add new, not existing user, I have the following error:

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>

my model looks like:

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 allows to edit the user, but fail whenI click on add button. What is wrong with that?

Kaczor
  • 53
  • 1
  • 8
  • This is one possible [lead](http://stackoverflow.com/questions/16953302/django-custom-user-model-in-admin-relation-auth-user-does-not-exist) I found in SO. It solved my problem when saving a new user to my extended User Model in Django 1.6 – Charlesliam Jan 19 '14 at 14:28
  • What's the content of your `AccountManager` class? – Omid Raha Jan 19 '14 at 14:52
  • I have the same problem and believe it is because of the 'ManyToManyField'; because without it my user admin site works fine – Martin Grohmann Sep 09 '14 at 13:36

0 Answers0