How do i change the warning message? (Updated)

I have the following model and the following form:

    class DeviceDetail(models.Model):
    ('17', '17'),
    ('21', '21'),
    ('22', '22'),
    ('23', '23'),
    ('24', '24'),
    ('25', '25'),
    ('26', '26'),
    ('27', '27'),
    ('28', '28'),
    ('29', '29'),
    ('30', '30'),

    DEV_MODS =(
        ('Catalyst 9606R', 'Catalyst 9606R'),
        ('C9300L-48T-4X', 'C9300L-48T-4X')

    hostname = models.CharField(max_length=50)
    mgt_interface = models.CharField(max_length=50)
    mgt_ip_addr = models.GenericIPAddressField(protocol='ipv4', unique=True)
    subnetmask = models.CharField(max_length=2, choices = SUBNET_CHOICES)
    ssh_id = models.CharField(max_length=50)
    ssh_pwd = models.CharField(max_length=50)
    enable_secret = models.CharField(max_length=50)
    dev_mod=models.CharField(max_length=50, choices = DEV_MODS) ##device_model replacement
    DD2DKEY = models.ForeignKey(Device, on_delete=models.CASCADE) ##The key to link up the tables
    def __str__(self):
        return self.hostnameclass 

class DeviceDetailForm(ModelForm):
    class Meta:
        model= DeviceDetail
        fields= ['hostname', 'mgt_interface', 'mgt_ip_addr', 'subnetmask', 'ssh_id', 'ssh_pwd', 'enable_secret', 'dev_mod']
        labels = {
            "mgt_ip_addr": "Management IP Address",
        widgets = {
            'enable_secret': forms.PasswordInput(),
            'ssh_pwd': forms.PasswordInput()

    def clean_hostname(self):
        hostname = self.cleaned_data['hostname']
        if len(hostname) < 8:
            raise forms.ValidationError(f'Hostname needs to be more than 8 character long, {hostname}')
        return hostname

When user submit a existing mgt_ip_addr, error will appear which doesnt allow saving. The error shows Management IP Address - Device detail with this Mgt ip addr already exists.**

The above line comes from this:

{{field.label}} - {{error}}

How to change this line to Management IP Address - already exists.** or is the {{error}} part fixed?

Hi CalvinTheCat, you should try setting the verbose_name on the model’s field.

The way I determined this was because I knew there were error messages used by Django. Searching the django repo on github for the default error messages, I found the unique error message.. Then searching for the field_label within the django repo revealed how the ValidationError is instantiated. There I could see verbose_name, then checked the doc’s for the model field options and sure enough, that’s where it can be set.

Thank you very much for the answer