Opened 18 years ago

Closed 16 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

Description

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/datastructures.py 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):
        return self.name
    
STATUSES = (
    (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 by Adrian Holovaty, 18 years ago

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 by Brian Rosner, 17 years ago

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 by James Bennett, 17 years ago

Resolution: fixed
Status: closedreopened

comment:4 by James Bennett, 17 years ago

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 by Jacob, 16 years ago

Triage Stage: UnreviewedAccepted

comment:6 by Brian Rosner, 16 years ago

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

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

comment:7 by Brian Rosner, 16 years ago

Keywords: nfa-fixed added

comment:8 by Brian Rosner, 16 years ago

Owner: Brian Rosner removed
Status: assignednew

comment:9 by Brian Rosner, 16 years ago

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