Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#9142 closed (invalid)

Validation shouldn't be coupled with validation...

Reported by: italomaia Owned by: nobody
Component: Forms Version: 1.0-alpha-2
Severity: Keywords: form validation decouple
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Well, very simple. If i have a ModelForm and i want to change a fields widget, i got to do as follows :

class MyForm(forms.ModelForm):
    my_field = forms.SomeField(widget=my_widget)
    class Meta:
        model = my_model

Well, when i do that, part of the form's validation goes away! Let's see a actual example:

class MyModel(models.Model):
    image = models.ImageField(uploat_to="some/path")

class MyForm(forms.ModelForm):
    image = forms.SomeField(widget=SimpleFileWidget)
    class Meta:
        model = MyModel

Well, using MyForm now will not validate if image is actually a image. That seems just wrong, to me.
Something like this would be nicier:

class MyModel(models.Model):
    image = models.ImageField(uploat_to="some/path")

class MyForm(forms.ModelForm):
    image = forms.SomeField(widget=SimpleFileWidget, validation=forms.ImageValidation)
    class Meta:
        model = MyModel

class MyForm(forms.ModelForm):
    image = forms.SomeField(widget=SimpleFileWidget, forms.get_validation(MyModel, "image")) # or something similar.
    class Meta:
        model = MyModel

Attachments (0)

Change History (2)

comment:1 Changed 6 years ago by italomaia

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

comment:2 Changed 5 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.