On Thursday, April 5, 2012 6:49:20 AM UTC-5, Chris Wilson wrote:
>
> Hi all,
>
> I've added this as a ticket but I wanted to make sure that the core
> and forms developers have a chance to see and interact with it, so I'm
> posting it here too. You can find the ticket at:
> <https://code.djangoproject.com/ticket/18064>
>
> Currently, if I want to tweak the properties of some fields in a
> ModelForm, I have to replace them in the subclass like this:
>
> {{{
> class DocumentForm(ModelForm):
> title =
> models.Document._meta.get_field('title').formfield(required=False)
> programs =
> models.Document._meta.get_field('programs').formfield(required=False)
> authors =
> models.Document._meta.get_field('authors').formfield(required=False)
> confidential =
>
> models.Document._meta.get_field('confidential').formfield(widget=AdminYesNoWidget)
> uploader =
> models.Document._meta.get_field('uploader').formfield(required=False)
> file =
>
> models.Document._meta.get_field('file').formfield(widget=AdminFileWidgetWithSize)
> }}}
>
You can already replace and tweak the fields in a way similar to what you
are proposing. For example, you can create a Form or ModelForm, and in the
__init__() you can do:
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.fields['title'] = models.Charfield(max_length=30, required=False)
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-developers/-/uyoFUewQrmIJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.