如何创建Django queryset过滤器以比较Django中两个不同表的特定值?

时间:2019-08-09 09:31:44

标签: python django django-models

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'

我有两个表“ Job”,另一个是“ employeeProfile”。我想比较和匹配两个表的“ title”,只想显示Job中存在的“ title”,而不显示“ employeeProfile”中的“ title”。这两个表位于两个不同的模型中。

0 个答案:

没有答案