I have a start_date
and end_date
fields in save_related
action of my Django Admin. I want to assign an error to end_date
when it is bigger than start_date
.
I have been looking docs, but don't find an example about that. Here is what i have tried so far:
My django admin code:
@admin.register(models.Event)
class EventAdmin(admin.ModelAdmin):
...
def save_related(self, request, form, formsets, change):
obj = form.instance
# Check validations
start_date = obj.start
end_date = obj.end
if end_date < start_date:
msg = u"End date should be greater than start date."
self._errors["end_date"] = self.error_class([msg])
return
...
But this code have this error: 'EventAdmin' object has no attribute 'error_class' How can I fix this?