# models.py
class Session(models.Model):
# other fields
dates = RecurrenceField(null=True)
In the django admin, I add a rule: weekly, Mondays.
I need to get all the Session dates of the current month (including those in the past). However, when I call between() with inc=True, and dtstart = the first day of the month (as decribed in the docs), then that dtstart is returned too (which is a Tuesday for March 2022):
# shell output:
In [7]: obj = Session.objects.all().first()
In [8]: for rule in obj.dates.rrules:
...: print(rule.to_text())
...:
hebdomadaire, chaque lundi # translates to: weekly, every Monday
In [9]: month_end
Out[9]: datetime.datetime(2022, 3, 31, 0, 0)
In [10]: month_start
Out[10]: datetime.datetime(2022, 3, 1, 0, 0)
In [11]: obj.dates.between(month_start,month_end,dtstart=month_start,inc=True,)
Out[11]:
[datetime.datetime(2022, 3, 1, 0, 0), # this is a Tuesday!
datetime.datetime(2022, 3, 7, 0, 0), # Monday
datetime.datetime(2022, 3, 14, 0, 0), # Monday
datetime.datetime(2022, 3, 21, 0, 0), # Monday
datetime.datetime(2022, 3, 28, 0, 0)] # Monday
In [12]: obj.dates.between(month_start,month_end,dtstart=month_start,inc=True,)[0].weekday()
Out[12]: 1
I have model with a RecurrenceField:
In the django admin, I add a rule: weekly, Mondays.
I need to get all the Session dates of the current month (including those in the past). However, when I call between() with inc=True, and dtstart = the first day of the month (as decribed in the docs), then that dtstart is returned too (which is a Tuesday for March 2022):