I have three models: Business, Offers and OfferPlan:
Business:

```
class Business(models.Model):
    name_of_business = models.CharField(max_length=255)

```

Offers:

```
class Offers(models.Model):
    business = models.ForeignKey(Business, related_name="business_offer",
                                 on_delete=models.CASCADE)
    title = models.CharField(max_length=255)
    subtext = models.CharField(max_length=255)

```

OfferPlan:

```
class OfferPlan(models.Model):
    WEEKDAYS = [
        (1, _("Monday")),
        (2, _("Tuesday")),
        (3, _("Wednesday")),
        (4, _("Thursday")),
        (5, _("Friday")),
        (6, _("Saturday")),
        (7, _("Sunday")),
    ]
    offer = models.ForeignKey(Offers, related_name="business_offer_plan",
                              on_delete=models.CASCADE)
    weekday = models.IntegerField(
        choices=WEEKDAYS,
    )
    from_hour = models.TimeField()
    to_hour = models.TimeField()

```

I have a ListView which search for businesses open based on different params such as city, category etc. I also want to now search by weekday, say which business is open on Monday will be displayed and which are not wont be displayed on that day. Weekday information is stored in OfferPlan and there could be multiple timings for the offers that day in OfferPlan table, but I want to query (filter, exclude) the businesses who has even a single entry on that weekday number.

Here is my ListView:

```
class SearchListView(ListView):
    template_name = 'search/search.html'
    model = Business

    def get_queryset(self):
        # queryset = Business.objects.filter(business_address__city=AppLocations.objects.first().city)
        if 'city' in self.request.GET:
            queryset = Business.objects.filter(business_address__city=self.request.GET.get('city'))

        if 'category' in self.request.GET:
            queryset = queryset.filter(category__code=self.request.GET.get('category'))

        # if 'date' not in self.request.GET:
        #     queryset = B
        raise
        return queryset

```

How could this be possible? Also looked into <https://docs.djangoproject.com/en/1.8/ref/models/conditional-expressions/> but not able to figure out. 

Thanks

---

Update 1
--------

---

After researching more in the web, I figured out this is how it could be achieved, but need to know for sure from other Django enthusiasts here that it is right.

```
queryset.filter(business_offer__business_offer_plan__weekday=1).annotate(count_entry=Count('business_offer__business_offer_plan__weekday')).filter(count_entry__gt=1)

```

---

Solution
--------

---

Jefferson's solution was tagged as right answer as it provided more insights, about which query is fast and what wrong was with my previous update, so here is the proper solution to which we both agreed:

`queryset.filter(business_offer__business_offer_plan__weekday=1).annotate(count_entry=Count('business_offer__business_offer_plan__weekday')).filter(count_entry__gte=1)`