Tobias McNulty wrote:
I regret and apologize that I'm arriving to this thread rather late.

To support the tradition, I'm apoligizing for this too :-). Though it's funny how everyone thinks they're "late" on a couple-of-days-old thread :-).

Anyway...

I too would opt for an implementation that makes model validation optional, i.e., a call that developers must explicitly make, if they choose, before saving a model.

I'm +1 on some way of validating a form without *fully* validating a model. But for a bit different reason that I didn't see in this thread yet.

The thing is that validating a ModelForm may not be strictly related to subsequent saving of an instance. A use-case:

I have a PreviewForm that generates a preview for a comment that user is writing in a form. It uses model fields to validate currently typed text and selected markup filter and then creates a model instance to do actual formatting:

    class PreviewForm(ModelForm):
        class Meta:
            model = Comment
            fields = ['text', 'markup_filter']

        def preview(self):
            comment = Comment(
                text = self.cleaned_data['text'],
                filter = self.cleaned_data['markup_filter'],
            )
            return comment.html()

It is then used like this:

    def preview_view(request):
        form = PreviewForm(request.POST)
        if form.is_valid():   # <- this now breaks
            return HttpResponse(PreviewForm.preview())

The thing is that the code has no intention to save an instance into a DB. It just needs it at application level. This is why I think that decisions on "full" vs. "partial" validation should not be bound to `save()`.

(FYI currently the first patch (Joseph's) in #12521 does fix this problem while the second patch (Honza's) doesn't. From a quick look this is beacuse the second patch only excludes fields from validation that listed in `exclude`).
-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" 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-developers?hl=en.


Reply via email to