import datetime
from django import admin
from django.db.models import Min, Max

class AvaliabilityAtDateListFilter(admin.SimpleListFilter):
  title = 'avaliability at date'
  parameter_name = 'date'

  def lookups(self, request, model_admin):
    stats = model_admin.model.objects.aggregate(Min('start'), Max('end'))
    start = stats.get('start__min')
    end = stats.get('end__max')
    days = list()
    while (start <= end):
      wynik.append(start)
      start = start + datetime.timedelta(days = 1)
    return [(d, d) for d in days]

  def queryset(self, request, queryset):
    if self.value():
      return queryset.filter(
        start__lte=self.value(), end__gte=self.value())
    else:
      return queryset