Django +4.1: How to show in templates the message from violation_error_message in UniqueConstraint

I'm lost...

In my model in models.py I have

class Project(models.Model):

... fields ...
... save ...
... etc ...

class Meta:
        constraints = [
            UniqueConstraint(
                 fields=['name', 'owner'], 
                 name='unique_name',
                 violation_error_message='my_error_message'
            )
        ]

In my class in views.py I have

class CreateProject(LoginRequiredMixin, CreateView):
    form_class = ProjectForm
    model = Project

    def form_valid(self, form):
            return super().form_valid(form)

In forms.py I have

class ProjectForm(forms.ModelForm):
    class Meta:
        model = Project
        fields = ("name", "description")

How do I display the message in violation_error_message when the constraint is not fulfilled?

Back to Top