On Mon, Feb 12, 2007 at 07:45:52AM -0800, RonnyPfannschmidt wrote: > > The actual method of creating Model related forms is a set of > functions returning form classes > > thats nice to use, but not very nice to extend > > Im proposing a Base class wich allows to pass models/instances to > generate forms, or inherit to extend the forms > > > default usage would be ModelForm(model=MyModel), > ModelForm(instance=myinstance) > or ModelForm(model=MyModel,object_id=myid) > > > extending would be something like > > class EntryForm(ModelForm): > Model = Entry > remove_fields=("some","private","fields") > # some fields of entry need custom formfields, so lets just set > them up > text = SaveXHTMLField(widget=TinyMCEWidget) > def clean_title(self): > pass # i should really do the check here > > > to make a AddForm i would just use EntryForm() > to get a EditForm i'd just use EntryForm(instance=e) or > EntryForm(object_id=entry_id) >
I've actually been using newforms with regards to models recently. I don't think there is a need for a new class to extend. Rather, you could easily do the same in models.form_for_model with extra arguemts (which don't exist at the moment). IE: form_for_model(Entry, not_required=['some','private','fields']) Also changing widgets is a breeze: EntryForm.fields['text'].widget = some.widget.class() You can still add clean methods after the fact by assigning functions to EntryForm.clean_title, ie: EntryForm.clean_title = lambda self: pass # do stuff -- Scott Paul Robertson http://spr.mahonri5.net GnuPG FingerPrint: 09ab 64b5 edc0 903e 93ce edb9 3bcc f8fb dc5d 7601
pgpFUDqZuIRBs.pgp
Description: PGP signature