I would like to filter the item in the select box of the add/change view in the admin.
My model:
class Decision(models.Model):
A1 = "A1"
A2 = "A2"
B1 = "B1"
B2 = "B2"
DECISION_CHOICES = [
(B1, _('B1 - Closed')),
(B2, _('B2 - Escalation of severity')),
(A1, _('A1 - Closed with warning')),
(A2, _('A2 - Review by certification committee')),
]
ncf = models.OneToOneField(Ncf, on_delete=models.PROTECT)
decision = models.CharField(max_length=2, choices=DECISION_CHOICES)
sanction = RichTextField(blank=True, null=True, default=None)
notes = models.TextField(blank=True, null=True)
...
in the admin (ModelAdmin) add/change page I would like to filter the choices of DECISION_CHOICES like something like this:
class DecisionAdmin(admin.ModelAdmin)
...
def ???(self, ....)
if ncf.severity == 'A':
DECISION_CHOICES = [
(A1, _('A1 - Closed with warning')),
(A2, _('A2 - Review by certification committee')),
]
else:
DECISION_CHOICES = [
(B1, _('B1 - Closed')),
(B2, _('B2 - Escalation of severity')),
]
...
Any Idea ? What can be overrided ?
Thx