[Answer]-Django – many-to-many through relationship

1πŸ‘

βœ…

I think the class Shift is not actually required. Since, it’s there just to give a shift a name, that can be done in class MachineryShift also.

class Machinery(models.Model):
    name = models.CharField(max_length=100)
    code = models.CharField(max_length=30)

class MachineryShift(models.Model):
    machinery = models.ForeignKey('Machinery')
    shift = models.Charfield(max_length=50)
    shift_start_time = models.TimeField()
    shift_end_time = models.TimeField()

This way, you can add as many shifts as you want for a machinery. Each machinery will have its own set of shifts.

πŸ‘€xyres

Leave a comment