Django Many to One Database Relation

I have two models like below.

class Applicant(models.Model):
    name = models.CharField(max_length=100)
    email = models.EmailField()
    resume = models.FileField()
    applied_for = models.ForeignKey(Job, on_delete=models.CASCADE)
class Job(models.Model):
    TYPE = [
        ('part_time', 'Part Time'),
        ('full_time', 'Full Time'),
        ('contract', 'Contract'),
    title = models.CharField(max_length=200)
    position = models.CharField(max_length=200)
    type = models.CharField(max_length=200, choices=TYPE, default=None)
    location = models.CharField(max_length=100)
    vacancy = models.PositiveIntegerField()
    description = models.CharField(max_length=200)
    skill_requirements = models.CharField(max_length=1000)
    education_requirements = models.CharField(max_length=1000)
    experience_requirements = models.CharField(max_length=1000)
    salary = models.PositiveIntegerField()

I want to store all the Applicant IDs in the Job model so that the admin can see all the applicants of a job in the admin panel. How can I do that?

The short answer is “You don’t”. That’s not the way to address this specific need.

The appropriate solution is the InlineModelAdmin class.

1 Like