I don’t use Field.validators much myself, but it seems that the Form clean method also calls Field.validators, so the redundancy is already there in the Form class. For consistency’s sake, I suggest we either add Model.clean_fieldname(), or we remove Form.clean_fieldname(). Both suggestions would certainly have issues with backwards compatibility.
From: [email protected] [mailto:[email protected]] On Behalf Of Jonas Haag Sent: Thursday, November 9, 2017 4:04 AM To: [email protected] Subject: #28788: Add support for Model.clean_<fieldname> Hi, I’m taking https://code.djangoproject.com/ticket/28788 to this mailing as per Tim’s request. I’m convinced we should add a Model.clean_<fieldname> method, the model equivalent to Form.clean_<fieldname>. Form validation has forms.Field.validators, Form.clean, and Form.clean_<fieldname>. Model validation has models.Field.validators, Model.clean, but no Model.clean_<fieldname>. Using Field.validators works, but is cumbersome and inelegant as you’ll have to put model validation logic outside the model definition. Model.clean_<fieldname> also helps you structure your validation logic, particularly if subclasses are involved. Backwards compatibility is an issue with my suggestion that is yet to be solved. We don’t want surprising calls to clean_XXX methods that were defined before this feature was introduced. I’m curious to hear what everyone else thinks! Jonas -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To post to this group, send email to [email protected]<mailto:[email protected]>. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/D7A48F7D-0A60-4ADF-B210-F73FA1F0B717%40lophus.org<https://groups.google.com/d/msgid/django-developers/D7A48F7D-0A60-4ADF-B210-F73FA1F0B717%40lophus.org?utm_medium=email&utm_source=footer>. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/42e405c8d5454699a09bea9960cc1c8d%40ISS1.ISS.LOCAL. For more options, visit https://groups.google.com/d/optout.
