mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-04-25 10:08:36 +02:00
fix(common:fields:month_year): unable to load data with a date
This commit is contained in:
@@ -20,7 +20,15 @@ class MonthYearModelField(models.DateField):
|
|||||||
# Set the day to 1
|
# Set the day to 1
|
||||||
return date.replace(day=1).date()
|
return date.replace(day=1).date()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ValidationError(_("Invalid date format. Use YYYY-MM."))
|
try:
|
||||||
|
# Also accept YYYY-MM-DD format (for loaddata)
|
||||||
|
return (
|
||||||
|
datetime.datetime.strptime(value, "%Y-%m-%d").replace(day=1).date()
|
||||||
|
)
|
||||||
|
except ValueError:
|
||||||
|
raise ValidationError(
|
||||||
|
_("Invalid date format. Use YYYY-MM or YYYY-MM-DD.")
|
||||||
|
)
|
||||||
|
|
||||||
def formfield(self, **kwargs):
|
def formfield(self, **kwargs):
|
||||||
kwargs["widget"] = MonthYearWidget
|
kwargs["widget"] = MonthYearWidget
|
||||||
|
|||||||
Reference in New Issue
Block a user