Django

Code

Ticket #1044 (new)

Opened 2 years ago

Last modified 3 months ago

Bug in admin panel

Reported by: wojtek@brandlay.com Assigned to: jkocherhans
Component: Admin interface Version:
Keywords: Cc:
Triage Stage: Accepted Has patch: 0
Needs documentation: 0 Needs tests: 1
Patch needs improvement: 0

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])

Attachments

Change History

05/04/06 23:20:47 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

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

09/18/07 11:09:07 changed 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.

09/18/07 11:19:02 changed by ubernostrum

  • status changed from closed to reopened.
  • resolution deleted.

09/18/07 11:19:36 changed by ubernostrum

  • owner changed from adrian to jkocherhans.
  • status changed from reopened to new.
  • needs_tests set to 1.

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

02/27/08 18:57:23 changed by jacob

  • stage changed from Unreviewed to Accepted.

Add/Change #1044 (Bug in admin panel)




Change Properties
Action