Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dates are somehow cached #20

Open
adi- opened this issue Jul 31, 2024 · 2 comments
Open

Dates are somehow cached #20

adi- opened this issue Jul 31, 2024 · 2 comments

Comments

@adi-
Copy link

adi- commented Jul 31, 2024

I need to enable only few dates in calendar and I initiate a form like this:

widgets = {
            'pickup_date': DatePickerInput(
                options=FlatpickrOptions(
                    enable=get_working_days_formated(
                        arrow.get(timezone.now().date()).shift(days=1),
                        arrow.get(timezone.now().date()).shift(days=2)
                    )
            ),
        }

Not sure if this is DatePicker problem or Django's/Python's caching, but when one day passes in real date, DatePicker still uses the same dates as were compiled for the first time. Any clues what could be wrong?

@lucas8107
Copy link

Hi, I don't know if you still need this, but I've faced a similar thing in the past. The issue is that your piece of code is probably executed when the server starts and doing so it fixes the result of timezone.now(). To solve the problem you need to provide the result in a lazy way. You can use lazy wrapper from django.utils.functional and instead of using timezone.now(), you use lazy(timezone.now, timezone.datetime)().

@adi-
Copy link
Author

adi- commented Nov 19, 2024

I don't rememberer now exactly, but it was a mistake of a initial value cached by python itself, I guess:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants