﻿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
22609	Allow specifying the form field when instantiating a model field	django@…	nobody	"I find myself having to do this time and time again, which really isn't DRY and won't be good for someone looking at my code in the future:


{{{
models.py

class MyModel(models.Model):
        HOME_DELIVERY = (
            (True, _(u""Home Delivery)),
            (False, _(u""Pickup (free)"")),
            )
    home_delivery = models.BooleanField(verbose_name=""Pickup/Home Delivery"",
                                     choices=HOME_DELIVERY, help_text=""Something."", blank=False)

forms.py

class MyModelForm(forms.ModelForm):
     class Meta:
          model = MyModel
     
     home_delivery = forms.ChoiceField(empty_label=None, choices=MyModel.HOME_DELIVERY,
                                  widget=forms.RadioSelect(), label=""Pickup/Home Delivery"")
}}}

In this example, the customisation that I am looking for is to use a radio widget, and to remove the 'empty value' (defaults to '--------')
In order to do so I have to redefine the home_delivery form field, which means I have to redefine both the choices *and* the label.

If another developer comes along and changes the verbose_name for the model, they'll (might) be stumped as to why the form label isn't changing.

I propose being allowed to specify the form in the model, so I could replace all of this with:

{{{
models.py

class MyModel(models.Model):
        HOME_DELIVERY = (
            (True, _(u""Home Delivery)),
            (False, _(u""Pickup (free)"")),
            )
    home_delivery = models.BooleanField(verbose_name=""Pickup/Home Delivery"",
                             choices=HOME_DELIVERY, help_text=""Something"", blank=False,
                             field=forms.ChoiceField(empty_label=None, widget=forms.RadioSelect()))
}}}

Cheers"	Uncategorized	closed	Uncategorized	1.6	Normal	wontfix			Unreviewed	0	0	0	0	0	0
