[Fixed]-What is the good practice to capture instantaneous model status in django?

1đź‘Ť

It sounds like status should be a seperate model/class with an FK to the robot, that way your robot has a “list” of all of its previous status’ and you just need to query the latest.

class ModelStatus(models.Model):
    robot = models.ForeignKey(Robot)
    power_status = models.PositiveSmallIntegerField(choices=POWER_STATUS)
    working_status = models.PositiveSmallIntegerField(choices=WORKING_STATUS)

You may want to add someway to order them other than the id but thats a decision I can’t really help you with.

If you don’t want the whole list then you can just have two OneToOneFields on your Robot

current_status = models.OneToOneField(ModelStatus, null=True)
previous_status = models.OneToOneField(ModelStatus, null=True)
👤Sayse

Leave a comment