[Fixed]-Postgis and geodjango *and* in filter

1👍

You can check if date of your object is in specified range using Django’s range lookup. It will look like this:

last_date = firstPointCheck.acquisition_date - timedelta(days=12)
next_date = firstPointCheck.acquisition_date + timedelta(days=12)

object_list2 = object_list.filter(center__distance_lte=(firstPointCheck.center, D(m=deltaCenter)), acquisition_date__range=[last_date, next_date])

range lookup in django is inclusive, that means range will include start and end value. It is equivalent to:

last_date = firstPointCheck.acquisition_date - timedelta(days=12)
next_date = firstPointCheck.acquisition_date + timedelta(days=12)

object_list2 = object_list.filter(center__distance_lte=(firstPointCheck.center, D(m=deltaCenter)), acquisition_date__lte=next_date, acquisition_date__gte=last_date)

Leave a comment