First of all I would like to say that I am extremely new to Django and Python.
I am writing an application using Django 2.0. I have two inheritances to the user: the patient and responsible. A patient needs a user to exist and a responsible needs a patient to exist. A responsible may have several patients but one patient may only have one responsible.
However I am having the following problem: A patient can not be responsible for himself and currently this happens. How can I stop this from happening?
patient model:
class Patient(models.Model):
user = models.OneToOneField(User, related_name='patient',
on_delete=models.CASCADE, unique=True)
(...)
responsible model:
class Responsible(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE,
limit_choices_to=Q(patient=None))
patient = models.ForeignKey(Patient, on_delete=models.CASCADE)
As you can see I'm using the "limit_choices_to" but it causes all users who are patients are not listed in the time I create a new responsible.