A
A
Almaz Akimov2021-12-02 19:04:25
Python
Almaz Akimov, 2021-12-02 19:04:25

Why doesn't fetching date_range by Django date work?

The model has date = models.DateField(null=True, verbose_name="Show Date")
The code works:

def show_dates():
    now = datetime.now()
    dates = Show.objects.exclude(date=datetime.now())
    return {"dates": dates}

Why doesn't this one work?
def show_dates():
    now = datetime.now()
    dates = Show.objects.filter(date__range=[datetime.now(), timedelta(days=7)])
    return {"dates": dates}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-12-02
@GolosB

Because date__range takes two dates, not a date and a delta.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question