ahmedaljawahiry / django-admin-site-search Goto Github PK
View Code? Open in Web Editor NEWA search (cmd+k) modal, for the Django admin UI, that searches your entire site.
License: MIT License
A search (cmd+k) modal, for the Django admin UI, that searches your entire site.
License: MIT License
At a minimum, run tests against all environments.
Extras:
Add explicit support for 5.0
Should support CTRL+K, if there's no CMD key.
Example: search bar at https://docs.djangoproject.com/en/4.1/
On tag push:
When the admin site is mapped to the root URL path, the adminSearchPath
returns a 301 response due to a missing trailing slash /
. As a result, the query q
is not passed through to the redirected URL and the search
method returns 0 values.
Set the admin site path to the root URL of the site in the project urls.py
urlpatterns = [
path('', admin.site.urls)
]
search.js:35
const adminSearchPath = adminPath ? `/${adminPath}/search/` : '/search';
Adding the trailing slash returns the correct 200 response along with the full search results.
const adminSearchPath = adminPath ? `/${adminPath}/search/` : '/search/';
All of my models that I want to have searchable already have a custom ModelAdmin. And all of them have a search_fields
property which determines which fields I want to have searchable. It would be super nice if django-admin-site-search could stick to this as well, so that search happens in the fields that I want to be searchable, no more and no less (solving #21). This should give a performance boost by not using literally every CharField
subclass, and should hopefully make searching through relations automatic as well (closing #20).
Great project by the way, the results look super slick.
Playwright or Cypress, to test FE <-> BE.
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.
Shouldn't be any issues, just update tox/setup/etc.
/admin/search
is currently hard-coded, which won't work if the admin site is registered under a different path.
Thank you for this project, it really comes in handy!
I think something might be wrong with how the search url is generated. My project is a bit different because it uses "/" as the path to the admin:
path("", admin.site.urls, name="home"),
So when I'm searching on the admin:index
page the search url is: /search/?q=asd
.
Now when I open the user groups it searches /auth/search/?q=asd
and says "An unexpected error occured".
Is there a configuration option for the search url?
I have many models that have a ForeignKey field to the User model. When I use django-admin-site-search to search for "[email protected]" by default I only get that user as a result, not also all the objects that belong to this user.
I can extend the filter like so:
class MyAdminSite(AdminSiteSearchView, admin.AdminSite):
site_header = "Sound Radix site admin"
def filter_field(self, query, field):
if isinstance(field, ForeignKey) and field.related_model is User:
return Q(**{f"{field.name}__email__icontains": query})
return super().filter_field(query, field)
And then I see many more results, as I'd expect. But it's kind of annoying to have to add these filters by hand for all possible related models (obviously I have ForeignKey fields to other models too). Can this be automated somehow?
Hey,
in my code I am using helper method to add prefix to ID to easily know from what model it comes.
Something like that:
class testmodel(models.Model):
def product_id(self):
return f'YNT{self.id}'
is it possible to add functionalities to the search bar that will also see help methods?
Thanks!
Search will raise an LookupError: App 'constance' doesn't have a 'Config' model.
error when the django-constance is used due the model name is Constance
but it's registered in the admin with Config
Name instead.
https://github.com/jazzband/django-constance/blob/master/constance/admin.py
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.