Created
October 17, 2017 10:02
-
-
Save nimasmi/59ec373c09d9a6c635787ba2ec791395 to your computer and use it in GitHub Desktop.
List today, start of next month, start of 2 months hence, etc. up to start of 12 months hence
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils.timezone import now | |
from dateutil.rrule import MONTHLY, rrule | |
def get_start_date_choices(): | |
today = now().date() | |
choices = [(today, "Now")] | |
for start_date in rrule(MONTHLY, count=12, dtstart=today, | |
bymonthday=1): | |
if start_date.date().year == today.year: | |
date_format = "%B" | |
else: | |
date_format = "%B %Y" | |
choices.append((start_date.date().isoformat(), start_date.strftime(date_format))) | |
return choices |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment