I have such a model
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 find all tasks between a date range and show whether the user can be applied, has already been applied or has been rejected. Information about the application is in the application 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 to work without making a left join on the application table in the database. any suggestions on how to make it work.
thanks
source share