Fair warning: I haven't been following this very closely, so I'm
probably way out in left field here. Feel free to look strangely at me
after I mention this. Would it be possible to use a factory pattern
for ModelForm?

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

class ArticleForm(forms.ModelForm(Article)):
    body = myapp.ReStructuredTextField()

That way, there's a sort of custom form that can be easily subclassed
to customize the form. This wouldn't be all that much different from
form_for_model, except that we could make sure - perhaps during
metaclass processing - that the Form.for_model class did in fact get
subclassed. It could simply raise an exception if instantiated without
being subclassed.

This just seems much cleaner than dealing with model attributes or
inner Meta classes. Fields and methods could be overridden like any
other class, with fields left out simply being inherited from the
parent class. The simple case would just look like this:

class ArticleForm(forms.Form.for_model(Article)):
    pass

And everything would Just Work, as long as they don't need more
flexibility. The only thing it doesn't handle yet is how to remove
fields from the customized form, but this might be as simple as
assigning the field to None or some new ExcludedField class or
something.

I also wholeheartedly agree with Joseph's use of a keyword argument to
accept an object instance, avoiding the need for a separate
for_instance method.

So, I like the overall idea, and I'm not particular on exactly how it
gets done. I just thought I'd throw my thoughts in on the subject.

-Gul

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