1

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])
M.Izzat
  • 1,086
  • 4
  • 22
  • 50
  • 1
    I don't think you can use `MonitorField`s with foreign key ids. You might try `monitor='status_id'` instead but I doubt that it would work. – Selcuk Nov 15 '17 at 06:27
  • thanks for the reply, but unfortunately it doesnt work – M.Izzat Nov 15 '17 at 06:32

1 Answers1

-1

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

ruddra
  • 50,746
  • 7
  • 78
  • 101
Vaibhav
  • 1,154
  • 10
  • 26
  • Hi @Vaibhav, my apologies, I edited my code when i made this post, the comma is in my code, it still not working and yes I already saw the post in the github as well, he has very similiar issue with me but no solution either. – M.Izzat Nov 15 '17 at 07:39
  • for me its working for same code, i created 2 model and when i am saving B (with [1]) its changing with new time i am giving – Vaibhav Nov 15 '17 at 07:42
  • 1) I created A-model (say - a1), 2) I create B-model with a1, 3) I modified b1 with different date and time and its working – Vaibhav Nov 15 '17 at 08:05
  • "3) I modified b1 with different date and time and its working" its should be auto update, when status is change to your case a1 – M.Izzat Nov 15 '17 at 08:17