benoitc/couchdbkit — Issue #110: CouchDbKit Django ext does not work with choices
Author: sirex
Created: 2011-11-12 19:44:49+00:00
State: open

Here is a code example::

# models.py

from couchdbkit.ext.django import schema

LICENCE_CHOICES = (
('gpl', _('GPL')),
('lgpl', _('LGPL')),
('bsd', _('BSD')),
)

class Work(schema.Document):
licence = schema.StringProperty(_('Licence'),
required=True, default='gpl', choices=LICENCE_CHOICES)

# forms.py

from couchdbkit.ext.django.forms import DocumentForm

from .models import Work

class WorkForm(DocumentForm):
class Meta:
document = Work

When I try to render this form, I get this error::

Error when calling the metaclass bases
cannot concatenate 'str' and 'list' objects

Exception Location: .../couchdbkit/ext/django/forms.py in
fields_for_document, line 160

This error is caused by this code::

if prop.choices:
if prop.default:
defaults['choices'] = prop.default_value() + list(
prop.choices)
defaults['coerce'] = prop.to_python

My default value is 'gpl', why default value is concatenated with choices? Is
this an error or a feature which I don't know how to use?