django-easy-audit
django-easy-audit copied to clipboard
Cannot use Admin inlines for `CRUDEvent`
The way CRUDEvent
is currently designed prevents generic inlines from functioning. Currently, object_id
is a CharField
. I'd propose that this be changed to a GenericForeignKey
so built-in Django functionality works as expected.
Expected to work:
class CrudEventInline(GenericTabularInline):
model = CRUDEvent
Error:
⋊> python manage.py check
SystemCheckError: System check identified some issues:
ERRORS:
<class 'app.model.admin.CrudEventInline'>: (admin.E301) 'easyaudit.CRUDEvent' has no GenericForeignKey.
I found a workaround for this, but it's stinky. I'm still of the opinion that object_id
should be a GenericForeignKey
.
from django.contrib.contenttypes.admin import (
GenericInlineModelAdminChecks,
GenericTabularInline,
)
from easyaudit.models import CRUDEvent
class CRUDEventGenericCheck(GenericInlineModelAdminChecks):
"""Override check against `ct_fk_field`.
easyaudit uses CharField instead of GenericForeignKey for `ct_fk_field`
"""
def _check_relation(self, obj, parent_model):
errors = super()._check_relation(obj, parent_model)
for error in list(errors):
if error.msg == "'easyaudit.CRUDEvent' has no GenericForeignKey.":
errors.remove(error)
return errors
class CRUDEventInline(GenericTabularInline):
model = CRUDEvent
checks_class = CRUDEventGenericCheck