[Django]-Django models : How to have variable number of foreign keys in a model?


Seems to me that what you need is a many-to-many relationship between Resume and Project, so I would suggest doing something like this:

class Project(models.Model):
    # Project fields

class Resume(models.Model):
    # Resume fields
    projects = models.ManyToManyFields(Project, related_name='resumes')

Note that a default association table will be defined by Django under the hood this way.

And now you have a model in which a resume can be related with multiple projects and vice versa.



You just need either a many to many field, or a foreign key from Model Project to Model Resume.

Leave a comment