Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use Admin inlines for CRUDEvent #261

Open
samamorgan opened this issue Oct 12, 2023 · 1 comment
Open

Cannot use Admin inlines for CRUDEvent #261

samamorgan opened this issue Oct 12, 2023 · 1 comment

Comments

@samamorgan
Copy link
Contributor

samamorgan commented Oct 12, 2023

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.
@samamorgan
Copy link
Contributor Author

samamorgan commented Feb 1, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant