On 11/12/07, Marty Alchin <[EMAIL PROTECTED]> wrote:
>
> On Nov 12, 2007 3:37 PM, Joseph Kocherhans <[EMAIL PROTECTED]> wrote:
> >     class MyForm(ModelForm):
> >         extra_field = SomeField()
> >
> >         class Options:
> >             model = MyModel
> >             fields = ['list', 'of', 'field', 'names']
> >
> >             def formfield_callback(db_field):
> >                 # return a formfield for the given db field
> >
> >         def save(self, commit=True):
> >             # override save if you need to
> >
> >         def clean(self):
> >             # override clean if you need to
> >
>
> Call me crazy, but why would formfield_callback even be needed in this
> case? Wouldn't it be possible supply customized fields as attributes
> of the class, alongside the extra_field assignments? It just seems
> counterintuitive to have some fields defined one way, with other
> fields defined in another way.

The admin (at least in newforms-admin) is still going to need
*something* like formfield_callback, but I haven't figured out the
details yet. In most cases though, you're right. I'll spell out the
details quickly though:

    class Article(models.Model):
        title = models.CharField(max_length=100)
        body = models.TextField

    class ArticleForm(models.Model)
        body = MyCustomBodyField() # override the default formfield

        class Options:
            model = Article

The resulting form here would still have 2 fields, title and body.
body would have a custom form field, and title would have the default
one.

Joseph

--~--~---------~--~----~------------~-------~--~----~
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