[Answered ]-How to use more than one foreign key in mapping django models

2👍

✅

Why you use person_id and pk in your Person model and pk and office_id in your Office model? The way I would do that:

class Office(models.Model):
    # office stuff here

class Person(models.Model):
    office = models.ForeignKey(Office)

class Apointment(models.Model):
    person = models.ForeignKey(Person)
    office = models.ForeignKey(Office)

Since django autogenerate the pk for each model I don’t see a reason to add those _id fields.

Leave a comment