JOB_TYPE = ( ('1', "Full time"), ('2', "Part time"), ('3', "Internship"), ) class Job(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) title = models.CharField(max_length=300) description = models.TextField() location = models.CharField(max_length=150) type = models.CharField(choices=JOB_TYPE, max_length=10) category = models.CharField(max_length=100) last_date = models.DateTimeField() skillRequired1 = models.CharField(max_length=100, default="") skillRequired2 = models.CharField(max_length=100, blank=True, null=True) work_experience = models.IntegerField(default=0) company_name = models.CharField(max_length=100) company_description = models.CharField(max_length=300) website = models.CharField(max_length=100, default="") created_at = models.DateTimeField(default=timezone.now) filled = models.BooleanField(default=False) def __str__(self): return self.title class EmployeeProfile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) title = models.CharField(max_length=300) location = models.CharField(max_length=150) type = models.CharField(choices=JOB_TYPE, max_length=10) work_experience = models.IntegerField(default=0) category = models.CharField(max_length=100) emailContact = models.CharField(max_length=100, default="") skill1 = models.CharField(max_length=100) skill2 = models.CharField(max_length=100) skill3 = models.CharField(max_length=100, blank=True) skill4 = models.CharField(max_length=100, blank=True) about_me = models.TextField() images = models.ImageField(upload_to='employeeProfiles', default='default.jpg') def __str__(self): return f'{self.user.first_name} Profile'
i have created two database tables 'Job' and other is "employeeProfile".. I want to Compare and match 'title' of both and want to show only those 'title' which is present in Job but not in 'employeeProfile'.These two tables are in two different Models.
i'd try something like that:
(will probably require to have a default=''
or blank=True
in the field declaration)
qs = EmployeeProfile.objects.filter(title='').exclude(user__title='')
you can resolve relation with the double __
you can also add null=True
to the title definition to be able to use:
qs = EmployeeProfile.objects.filter(user__title__isnull=False, title__isnull=True)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.