'Is there a way to give alert in django admin page for not matching some constraints while adding data in fields?

Basically in my simple website I add some college fest details like name, date etc. from admin page, not from the website.

This is my Fest model

class Fest(models.Model):
    FEST_CHOICES=[
        ('CUL','Cultural'),
        ('TEC','Technical'),
        ('COL','College'),
        ('SPO','Sports'),
    ]
    id=models.IntegerField(primary_key=True)
    name=models.CharField(max_length=50)
    clg_id=models.ForeignKey(College,on_delete=models.CASCADE)
    fest_type=models.CharField(choices=FEST_CHOICES,default='COL',max_length=10)
    fest_desc=models.TextField(default='This is a fest')
    start_date=models.DateField(default='2022-01-01')
    end_date=models.DateField(default='2022-02-01')
    event_nos=models.IntegerField()
    org_id=models.ManyToManyField(Organizer)
    image=models.ImageField(default='default.jpg',upload_to='fest_pics')

Currently for start_date and end_date I've given a check constraint under the model itself

class Meta:
    constraints = [
        CheckConstraint(
            check = Q(end_date__gte=F('start_date')), 
            name = 'check_start_date',
        )
    ]
    db_table='fest'

But the problem is it redirects to a page showing IntegrityError, constraint is violated.

How can I make it so that it gives an alert or message in admin page itself if end_date is lesser than start_date?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source