﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
1044	Bug in admin panel	wojtek@…		"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])
}}}"	defect	closed	contrib.admin	newforms-admin	normal	fixed	nfa-fixed		Accepted	0	0	1	0	0	0
