Hello
To summarize, the validation defined in DRF serializers won't be called 
during form validation in the Django Admin interface because the Admin uses 
its own validation methods based on forms and models. If you want 
consistent validation across the board, you should either place the 
validation in the model’s clean method or use a custom form that leverages 
your DRF serializers' validation logic. This way, you ensure that the same 
rules apply whether the model instance is being created or updated via the 
DRF API or the Django Admin interface.

On Monday, June 24, 2024 at 6:32:00 AM UTC+3 cjim...@gmail.com wrote:

> If a serializer implemented based on the Django Rest framework 
> ModelSerializer class defines a validator, will it be called when an API 
> endpoint is accessed through the standard Django admin interface?
>
> I have implemented validate function(s) in my backend implemented using 
> the Django Rest framework. The validate function is called without a 
> problem if I use a curl command or other React-based frontend to access the 
> backend endpoints. However, if I use a browser to access the backend via 
> the /admin endpoint, the validate functions are not called.
>
> Near as I can figure, the Admin interface will call single field 
> validation functions in the model from 
> db.models.fields.__init__.run_validators() 
> which is called by db.models.fields.__init__.clean 
> which is called by db.models.base.clean_fields
> which is called by db.models.base.full_clean
> which is called by forms.models._post_clean
> which is called by forms.forms.full_clean
> and so on.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/f5d6cebe-fbab-4dc0-a363-da365b2c8492n%40googlegroups.com.

Reply via email to