[Fixed]-How to avoid two ForeignKeys in django model if one of them will be NULL in every case

1๐Ÿ‘

โœ…

I think a simple solution would be to combine Supervisor and Salesman into 1 model. You could simply call this Staff and create a field called is_supervisor which would differentiate supervisors from regular salesmen.

To do this, you would set up your model something like this:

class Product(models.Model):
  staff = models.ForeignKey(Staff, null=True)
  # other stuff

class Staff(models.Model):
  name = models.CharField(max_length=100)
  supervisor = models.ForeignKey('self', null=True)
  is_supervisor = models.BooleanField()
๐Ÿ‘คWritten

Leave a comment