that wouldnt remove the strict distinction betwen form_for_model
and form_for_instance (the only difference i see, is that one of them
has a initial instance

and i really would like to have a base class, since i like to avoid
monkey-patching

using the function result as a base-class would be an acceptable
solution

but i would apreciate a different use-pattern

default forms:

MyForm = modelForm(model)

MyForm() #for add-forms
MyForm(instance=foo) or Myform(object_id=bar) # edit forms

class Myform(modelForm(model)):
    # extend me :)
    pass

cause i dislike recreating the form classes every time someone wants
to edit something


On 12 Feb., 17:43, "Honza Král" <[EMAIL PROTECTED]> wrote:
> On 2/12/07, Scott Paul Robertson <[EMAIL PROTECTED]> wrote:
>
>
>
> > 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
>
> or, since we are in python, this should also work:
>
> class MyModelForm( forms_for_model(Model) ):
>     #define what you want here...delete fields in __init__ etc.
>
> --
> Honza Král
> E-Mail: [EMAIL PROTECTED]
> ICQ#:   107471613
> Phone:  +420 606 678585


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to