Django MonitorField() not working with Foreign Key if when condition is added

450 Views Asked by At

Greeting, as mention in the question, my MonitorField stop updating the date when I add a when condition in it, below is my code :

class A(models.Model):

    name = models.CharField(max_length=50, unique=True)

    def __str__(self):
        return self.name

class B(models.Model):
 status = models.ForeignKey(A, on_delete=models.CASCADE, default=4, null=True)
 monitor = fields.MonitorField(monitor='status', when=[1])
1

There are 1 best solutions below

4
Vaibhav On

You missed comma between monitor and when field

monitor = fields.MonitorField(monitor='status', when=[1])

Check this issue of django-model-utils on github if above doesnt work LINK