Field validation with access to the pk of the model.

Is it possible to make a field validator that has access to the pk of the model?

I need it to validate that the field is unique, the unique option is case sensitive so it doesn’t work for me.
The UniqueConstraint option displays the error message disconnected from the field in the form so it’s not a good option either.
I’m currently validating it on the form but I have quite a lot of code repeated in many forms.

Have you checked the constraints docs?

Yes, it works but it shows the error message disconnected from the field in the form, it causes confusion to have all the messages bound to the form fields except this one.

The documentation says that it can be used in the following way but it generates an incorrect sql statement:
UniqueConstraint(Lower(‘name’).desc(), name=‘unique_lower_name’)

You have to use it without ordering.
UniqueConstraint(Lower(‘name’), name=‘unique_lower_name’)