Opened 10 years ago

Closed 7 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: UI/UX:

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 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:2 Changed 8 years ago by brosner

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 8 years ago by ubernostrum

  • Resolution fixed deleted
  • Status changed from closed to reopened

comment:4 Changed 8 years ago by ubernostrum

  • Needs tests set
  • Owner changed from adrian to jkocherhans
  • Status changed from reopened to new

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

comment:5 Changed 8 years ago by jacob

  • Triage Stage changed from Unreviewed to Accepted

comment:6 Changed 7 years ago by brosner

  • Owner changed from jkocherhans to brosner
  • Status changed from new to assigned
  • Version set to newforms-admin

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

comment:7 Changed 7 years ago by brosner

  • Keywords nfa-fixed added

comment:8 Changed 7 years ago by brosner

  • Owner brosner deleted
  • Status changed from assigned to new

comment:9 Changed 7 years ago by brosner

  • Resolution set to fixed
  • Status changed from new to closed

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