In my Django model there should be only one value that can be the main one while the rest are optional.
In my model:
@with_author
class BOMVersion(models.Model):
name = models.CharField(max_length=200,null=True, blank=True)
description = models.TextField(null=True, blank=True)
tomaterial = models.ForeignKey(Material, related_name = 'tomaterial')
status = models.CharField(max_length=1, choices=STATUS_CHOICES)
BOM_CHOICES = (
('M','Main'),
('A','Additional'),
)
I should be able to populate this model with data such that only one of the rows' status
will have the value Main while the rest will always be Additional. (It is totally the Radio button functionality when only value can be selected.)
For example:
1 v1 ...A
2 v2 ...M
3 v3 ...A
.........
n vn ...A
I came up with a workaround where all the values added will always be additional and will have a separate UI with a radio button where the user will select what value should be the main.
But was wondering is there a way to apply this logic to a Django model directly?