Re: Declarative syntax for widgets in ModelForm

2008-09-29 Thread Ivan Sagalaev
Brian Beck wrote: > I think your model_field helper being built-in (short for > x._meta.get_field(y).formfield(**params), which is not very pretty) > would be the best solution here. In my experience, customizing just > the widget for a model field is just as common as changing just the > label,

Re: Declarative syntax for widgets in ModelForm

2008-09-29 Thread Ivan Sagalaev
SmileyChris wrote: > I do feel like it leads to slippery slope though. LikeMichael said, > "why stop at widgets?" I often need to change labels and help text > too. Full customization already can be done by specifying fields directly in a form class. In my experience widgets are just very

Re: Declarative syntax for widgets in ModelForm

2008-09-29 Thread Julien Phalip
On Sep 29, 11:40 pm, Julien Phalip <[EMAIL PROTECTED]> wrote: > On Sep 29, 10:46 pm, zvoase <[EMAIL PROTECTED]> wrote: > > > Why not do something like this: > > > class MyForm(forms.ModelForm): > > class Meta: > > fields = { > > 'text':

Re: Declarative syntax for widgets in ModelForm

2008-09-29 Thread Julien Phalip
On Sep 29, 10:46 pm, zvoase <[EMAIL PROTECTED]> wrote: > Why not do something like this: > > class MyForm(forms.ModelForm): > class Meta: > fields = { > 'text': forms.CharField(widget=forms.Textarea(), ...), > 'other_field': None, > } This syntax would

Re: Declarative syntax for widgets in ModelForm

2008-09-29 Thread zvoase
I understand the motivation for this, and support the idea, but I think the implementation is a little repetitive: class MyForm(forms.ModelForm): class Meta: fields = # LIST OF FIELDS widgets = # DICT OF FIELD NAMES : WIDGETS Why not do something like this: class

Re: Declarative syntax for widgets in ModelForm

2008-09-29 Thread SmileyChris
Bah, it was just prototype code but point taken ;) I do feel like it leads to slippery slope though. LikeMichael said, "why stop at widgets?" I often need to change labels and help text too. On Sep 29, 8:56 pm, Ivan Sagalaev <[EMAIL PROTECTED]> wrote: > SmileyChris wrote: > > I've always just

Re: Declarative syntax for widgets in ModelForm

2008-09-29 Thread Ivan Sagalaev
SmileyChris wrote: > I've always just done this by doing: > > MyForm(ModelForm) > model = MyModel > def __init__(self, *args, **kwargs): > self.fields['name'].widget = Textarea() # or whatever You've forgot to call `super` :-). I know that it's only an example but it adds

Re: Declarative syntax for widgets in ModelForm

2008-09-28 Thread SmileyChris
On Sep 28, 1:13 am, Ivan Sagalaev <[EMAIL PROTECTED]> wrote: > Joseph Kocherhans wrote: > > On Sun, Jul 6, 2008 at 6:27 AM, Ivan Sagalaev > > <[EMAIL PROTECTED]> wrote: > >> ## Proposal > > >> To fix this I was thinking along the lines of: > > >>     class ArticleForm(ModelForm): > >>        

Re: Declarative syntax for widgets in ModelForm

2008-09-27 Thread Ivan Sagalaev
Joseph Kocherhans wrote: > On Sun, Jul 6, 2008 at 6:27 AM, Ivan Sagalaev > <[EMAIL PROTECTED]> wrote: >> ## Proposal >> >> To fix this I was thinking along the lines of: >> >> class ArticleForm(ModelForm): >> class Meta: >> model = Article >> fields =

Re: Declarative syntax for widgets in ModelForm

2008-07-06 Thread Ivan Sagalaev
Michael Elsdörfer wrote: > Why stop at widgets? Basically, because I was struggling with widgets many times but didn't have any practical needs for changing a label, for example. I don't say it's useless or something but I just can't defend it from my experience. > By the way, IIRC the

Re: Declarative syntax for widgets in ModelForm

2008-07-06 Thread Michael Elsdörfer
>      class ArticleForm(ModelForm): >          class Meta: >              model = Article >              fields = ['author', 'text'] >              widgets = { >                  'text': Textarea(...), >              } Why stop at widgets? Let's say I want to change just the label of a field,

Re: Declarative syntax for widgets in ModelForm

2008-07-06 Thread Yuri Baburov
On Sun, Jul 6, 2008 at 8:44 PM, Julien Phalip <[EMAIL PROTECTED]> wrote: > As for dynamic choices, I think that still belongs to the init method, > not the Meta class. No, I mean kinda dynamic_FIELD_choices methods, as it was suggested for ModelAdmin. > On Jul 6, 11:20 pm, Ivan Sagalaev <[EMAIL

Re: Declarative syntax for widgets in ModelForm

2008-07-06 Thread Julien Phalip
To add to the case, redefining fields in ModelForm can introduce serious problems and do more than just compromise DRY. E.g. if you have a model field that's optional (blank=True), you need not to forget to add 'required=False' to your form field re- declaration... As for dynamic choices, I

Re: Declarative syntax for widgets in ModelForm

2008-07-06 Thread Yuri Baburov
Hi Ivan, 1) You missed making a subclass as third option in your initial post (and preferred one), that's why i suggested it. 2) "Sure everyone can subclass anything or patch Django installation" is not much realistic statement: for some things, it's much easier than for other ;) 3) Why I think

Re: Declarative syntax for widgets in ModelForm

2008-07-06 Thread Ivan Sagalaev
Yuri Baburov wrote: > And before it's landed into the trunk (i hope it will ;) ) you can > make your own subclass of ModelForm which does exactly what you > proposed, and then subclass it everywhere ;) Yuri, it's a bit redundant note :-). Sure everyone can subclass anything or patch Django

Re: Declarative syntax for widgets in ModelForm

2008-07-06 Thread Yuri Baburov
Hi Ivan, Yes, together with dynamic choices will perform great (on init, developers might assign some options to widgets...). And before it's landed into the trunk (i hope it will ;) ) you can make your own subclass of ModelForm which does exactly what you proposed, and then subclass it

Re: Declarative syntax for widgets in ModelForm

2008-07-06 Thread Julien Phalip
> ## Proposal > > To fix this I was thinking along the lines of: > >      class ArticleForm(ModelForm): >          class Meta: >              model = Article >              fields = ['author', 'text'] >              widgets = { >                  'text': Textarea(...), >              } > > Sound

Re: Declarative syntax for widgets in ModelForm

2008-07-06 Thread Ivan Sagalaev
Steve Holden wrote: > What's CSS for? For styling. Choosing widgets has nothing to do with styling. My cols and rows for textarea is just an example that, incidently, can be emulated with CSS. But often you want to use a different widget altogether, say, a set of radio buttons instead of

Re: Declarative syntax for widgets in ModelForm

2008-07-06 Thread Steve Holden
Ivan Sagalaev wrote: > Hi, everyone! > > I was recently refactoring some old code to use a ModelForm and was > stuck at an issue that we don't have a simple way to say "this form has > these fields from a model but with other widgets". > > For example I have an Article model that I want to

Declarative syntax for widgets in ModelForm

2008-07-06 Thread Ivan Sagalaev
Hi, everyone! I was recently refactoring some old code to use a ModelForm and was stuck at an issue that we don't have a simple way to say "this form has these fields from a model but with other widgets". For example I have an Article model that I want to edit in a form: class