Files
WYGIWYH/app/apps/common/widgets/month_year.py
2024-10-10 22:37:10 -03:00

17 lines
377 B
Python

from datetime import datetime, date
from django import forms
class MonthYearWidget(forms.DateInput):
"""
Custom widget to display a month-year picker.
"""
input_type = "month" # Set the input type to 'month'
def format_value(self, value):
if isinstance(value, (datetime, date)):
return value.strftime("%Y-%m")
return value