mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-01-11 20:00:26 +01: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
|
||||
return date.replace(day=1).date()
|
||||
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):
|
||||
kwargs["widget"] = MonthYearWidget
|
||||
|
||||
Reference in New Issue
Block a user