thanks!

a subclass of newforms.BaseForm did the job!

lowshoe

On Feb 20, 11:35 pm, presclark <[EMAIL PROTECTED]> wrote:
> Hello, I was having a similar, but slightly different problem.
>
> My hangup was that the form_change form wasn't being populated. It
> seems that the optional 'form' parameter for form_for_(model/instance)
> should probably be a subclass of newforms.BaseForm, and not of
> newforms.ModelForm.
>
> seehttp://code.djangoproject.com/ticket/3632
>
> So your test-case might become:
>
> class DocumentForm(forms.BaseForm):
>     pass
>
> Still in the process of working on this myself, but I hope it helps,
>
> preston
>
> On Feb 12, 6:14 am, lowshoe <[EMAIL PROTECTED]> wrote:
>
> > hi,
>
> > i'm trying to use acustomform for one of my models inside the admin
> > interface . i need this to docustomvalidation.
>
> > so far, i have created a DocumentForm that inherits from
> > newforms.ModelFormand define my Model as model attribute inside the
> > Meta class (as seen 
> > athttp://www.djangoproject.com/documentation/modelforms/)
>
> > ---
> > from django import newforms as forms
>
> > class DocumentForm(forms.ModelForm):
> >     class Meta:
> >         model = models.Document
> > ---
>
> > then i overwrote form_add and form_change in my Options class:
>
> > ---
> > from django.contrib.admin import ModelAdmin
>
> > class DocumentOptions(ModelAdmin):
>
> >     def form_add(self, request):
> >         if self.declared_fieldsets:
> >             fields = flatten_fieldsets(self.declared_fieldsets)
> >         else:
> >             fields = None
> >         return forms.form_for_model(self.model, form=DocumentForm,
> > fields=fields,
>
> > formfield_callback=self.formfield_for_dbfield)
>
> >     def form_change(self, request, obj):
> >         if self.declared_fieldsets:
> >             fields = flatten_fieldsets(self.declared_fieldsets)
> >         else:
> >             fields = None
>
> >         return forms.form_for_instance(obj, form=DocumentForm,
> > fields=fields,
>
> > formfield_callback=self.formfield_for_dbfield)
>
> > admin.site.register(models.Document, DocumentOptions)
> > ---
>
> > but now i get an error when trying tro add or edit a document:
>
> > Exception Type:         TypeError
> > Exception Value:        'NoneType' object is not callable
> > Exception Location:     /usr/lib/python2.5/site-packages/django/newforms/
> > models.py in __init__, line 270
>
> > Traceback:
> > [..]
> > File "/usr/lib/python2.5/site-packages/django/newforms/models.py" in
> > __init__
> >   270.             self.instance = opts.model()
>
> > i don't understand why calling opts.model() fails. this should be
> > exactly my Document model which i defined inside the Meta class. Did i
> > miss something or whats wrong there?
>
> > regards, lowshoe
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
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-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to