Opened 13 years ago

Closed 10 years ago

#1044 closed defect (fixed)

Bug in admin panel

Reported by: wojtek@… Owned by:
Component: contrib.admin Version: newforms-admin
Severity: normal Keywords: nfa-fixed
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no


With the model below adding a client in the admin panel fails with:

AttributeError at /admin/crm/clients/add/
'list' object has no attribute 'setdefault'
Request Method: 	POST
Request URL: 	http://localhost:8000/admin/crm/clients/add/
Exception Type: 	AttributeError
Exception Value: 	'list' object has no attribute 'setdefault'
Exception Location: 	/opt/adminpanel/django/utils/ in __init__, line 182

 176.  """
 177. def __init__(self, key_to_list_mapping):
 178. for k, v in key_to_list_mapping.items():
 179. current = self
 180. bits = k.split('.')
 181. for bit in bits[:-1]:

 182. current = current.setdefault(bit, {}) ...

 183. # Now assign value to current position
 184. try:
 185. current[bits[-1]] = v
 186. except TypeError: # Special-case if current isn't a dict.
 187. current = {bits[-1]: v}
class Client(meta.Model):
    name = meta.CharField(maxlength = 32)
    email = meta.EmailField()
    contact = meta.TextField(maxlength = 1024)
    added = meta.DateField(auto_now_add = True)
    class META:
        admin = meta.Admin(
            list_display = ['name', 'email'],
    def __repr__(self):
    (1, 'Nowy'),
    (5, 'Czeka na decyzje (wewn)'),
    (10, 'Czeka na decyzje (zewn)'),
    (15, 'Obsluzony'),
class Contact(meta.Model):
    client = meta.ForeignKey(Client, edit_inline=meta.STACKED, num_in_admin=1)
    status = meta.IntegerField(choices = STATUSES)
    description = meta.TextField(core = True)
    added = meta.DateField(auto_now_add = True)
    file = meta.FileField(upload_to = MEDIA_ROOT, blank = True)

    class META:
        admin = meta.Admin(
            list_select_related = True, 
            list_display = ('client', 'status', 'description', 'get_link'),
            list_filter = ('client', 'status' ), 
            ordering = ('status', ),
            search_fields = ('description', ))

    def get_link(self):
        from os.path import basename
        from django.conf.settings import MEDIA_URL
        return self.file and '<a href="%s/%s">Plik</a>' % (MEDIA_URL, basename(self.get_file_url()),) or ''
    get_link.allow_tags = True
    def __repr__(self):
        return "%s, %s" % (self.get_client().name, self.description[:40])

Change History (9)

comment:1 Changed 13 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

Is this still an issue with the new trunk? Please reopen with updated info if that's the case.

comment:2 Changed 11 years ago by Brian Rosner

This came up in IRC and I was able to verify that this issue is still a problem with trunk (r6373). The newforms-admin branch will more than likely fix this, but if not here is what i discovered. When you have an edit_inline model named the same thing as a field in the parent model the DotExpandedDict fails since there is name clashing. Just rename the edit_inline model and it works.

comment:3 Changed 11 years ago by James Bennett

Resolution: fixed
Status: closedreopened

comment:4 Changed 11 years ago by James Bennett

Needs tests: set
Owner: changed from Adrian Holovaty to jkocherhans
Status: reopenednew

Reassigning to Joseph so he can exercise any necessary unit tests to prove this is fixed in newforms-admin.

comment:5 Changed 11 years ago by Jacob

Triage Stage: UnreviewedAccepted

comment:6 Changed 11 years ago by Brian Rosner

Owner: changed from jkocherhans to Brian Rosner
Status: newassigned
Version: newforms-admin

Taking this ticket. I will check this on newforms-admin.

comment:7 Changed 11 years ago by Brian Rosner

Keywords: nfa-fixed added

comment:8 Changed 11 years ago by Brian Rosner

Owner: Brian Rosner deleted
Status: assignednew

comment:9 Changed 10 years ago by Brian Rosner

Resolution: fixed
Status: newclosed

This is no longer a problem since the merge of newforms-admin in [7967].

Note: See TracTickets for help on using tickets.
Back to Top