[Fixed]-How to make sure only one row is enabled?

1👍

You could define a pre_save signal for that model. In there if you see that the enabled flag is set to true, you query on all configs currently are enabled. You disable all of them and save current instance:

def unique_enabled(sender, instance, **kwargs):
    if instance.enabled:
        for other in Config.objects.filter(enabled=True).exclude(id=instance.id):
            other.enabled = False
            other.save()

Leave a comment