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

How to exclude certain models? #21

Open
kevinrenskers opened this issue Mar 1, 2024 · 2 comments
Open

How to exclude certain models? #21

kevinrenskers opened this issue Mar 1, 2024 · 2 comments

Comments

@kevinrenskers
Copy link

kevinrenskers commented Mar 1, 2024

At the moment every model that's registered with the admin site is searched through, but I have some models that I'd like to exclude. They're not interesting to search through and it'll definitely help speed up the search.

As an aside, are there ways to speed up the search? Every query takes about 5 seconds to complete on my local machine, and it'll be slower on the production server for sure.

@kevinrenskers
Copy link
Author

Ah, found it.

class MyAdminSite(AdminSiteSearchView, admin.AdminSite):
    def match_objects(self, query, model_class, model_fields):
        if model_class in [ModelOne, ModelTwo]:
            return Q()
        return super().match_objects(query, model_class, model_fields)

And yes, this has already brought the search down to less than 2 seconds :)

@ahmedaljawahiry
Copy link
Owner

Yep - that's the way 👍

I've pondered on making this a bit simpler, maybe with an attribute on the admin class. Will be much simpler to do that once there's some implementation for #22, so will revisit then.

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

2 participants