I have a model like so
class Job(models.Model):
description = models.CharField(max_length=255)
user = models.ForeignKey(User)
date = models.DateField()
slot = models.CharField(max_length=10, choices=SLOT_CHOICES)
location = models.ForeignKey(Location)
objects = JobManager()
searches = geomodels.GeoManager()
class Meta:
verbose_name_plural = "Job"
unique_together = ('date', 'slot', 'user')
def __str__(self):
return "{0}-{1}".format(self.user.first_name, self.date)
class Applied(models.Model):
user = models.ForeignKey(User)
job = models.ForeignKey(Job, null=True, blank=True)
action_taken = models.BooleanField(default=False)
is_declined = models.BooleanField(default=False)
class Meta:
verbose_name_plural = "Job Applications"
unique_together = ('user', 'job', )
I want to search for all the jobs between a date range and show whether a user can apply, has already applied or has been declined. The application information is in applied model.
jobs = Job.searches.filter(**kwargs)\
.filter(date__range=(date_from, date_to),
visibility=VisibilityStatus.PUBLIC,
status=JobStatus.AVAILABLE)\
.prefetch_related('applied_set')\
.select_related('user__surgeryprofile__location')\
.order_by('date')
But I can't get it work, its not doing a left join on applied table in the database. any suggestions how to get it working.
Thanks