1

I've got a model called Couple. Couple describes the relationship between two Auth.User records.

class Couple(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    partner_one = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING, related_name='partner_one')
    partner_two = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.DO_NOTHING, related_name='partner_two')

I'm having trouble referencing the partner in a reliable from their user model because now I need to know which is partner one, partner two. This is obviously not an elegant solution. Is there a better way to achieve what I'm trying to do here?

ichramm
  • 6,437
  • 19
  • 30
JDKrsa
  • 11
  • 2
  • Check out the answers here, they present solutions to your exact problem. https://stackoverflow.com/questions/38261145/django-onetoone-field-to-self – Beikeni Apr 30 '22 at 21:30
  • Woah, @Beikeni that works a charm. I searched and couldn't find this. Thank you! – JDKrsa May 01 '22 at 08:20
  • Does this answer your question? [Django OneToOne field to self](https://stackoverflow.com/questions/38261145/django-onetoone-field-to-self) – aaron May 01 '22 at 10:36

0 Answers0