How can i limit the number of objects we can save by with a condition and without a condition in django?

Viewed 13

What is meant is, I want to save only one object with is_featured field true, if user tried to save another object with is_featured field true it needs to give a prompt, How can i accomplish that in django any idea?

class Event(BaseModel):
    title = models.CharField(max_length=200)
    time = models.TimeField()
    date = models.DateField()
    location = models.CharField(max_length=200)
    location_url = models.URLField()
    description = models.TextField()
    is_featured = models.BooleanField(default=False)
    image = VersatileImageField('Image', upload_to="web/events")

    class Meta:
        db_table = 'web_event'
        verbose_name = ('Event')
        verbose_name_plural = ('Event')
        ordering = ('auto_id',)

    def __str__(self):
        return str(self.title)
0 Answers
Related