﻿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
15773	MultiValueField could be more convenient	Aryeh Leib Taurog <vim@…>	nobody	"It seems to me that the !MultiValueField could be a lot more useful.  I'm assuming the !SplitDateTimeField code exemplifies the normal use case, and I see two things here that bother me.

1. To use !MultiValueField, coder '''must''' create and assign a widget class.  Maybe I'm just lazy because the other Field classes seem to provide reasonable defaults, but couldn't this field provide a reasonable default as well?

2. `compress` must be defined on the Field class, but `decompress` must be defined on the Widget class.  I don't know if I'd call this a violation of DRY, but it seems to me it  would be much nicer to put these two together, since one is the inverse of the other.  Obviously there's nothing preventing me from putting my !MultiWidget subclass and !MultiValueField subclass together, but if I separate the Widgets from the Fields, as the django source has done, then I introduce room for maintenance errors.

I guess this is mainly about convenience.  We '''do''' like making good development practice more convenient.

My suggestion for addressing these two points is below.  Thanks for reading.

{{{#!python
from django.forms import fields
from django.forms import widgets

class MultiValueFieldWidgetDescriptor(object):
    def __get__(self, instance, owner):
        widget_base = getattr(owner, 'widget_base', widgets.MultiWidget)
        class MyWidget(widget_base):
            def __init__(self, attrs=None):
                widgets = [f.widget for f in instance.fields]
                super(MyWidget, self).__init__(widgets, attrs)

            decompress = owner.decompress.__get__(self)

        return MyWidget

class MultiValueField(fields.MultiValueField):
    widget = MultiValueFieldWidgetDescriptor()
}}}"	New feature	closed	Forms	1.3	Normal	needsinfo		vim@…	Unreviewed	0	0	0	0	0	0
