Git Product home page Git Product logo

django-admin-site-search's People

Contributors

ahmedaljawahiry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

django-admin-site-search's Issues

Setup CI

At a minimum, run tests against all environments.

Extras:

  • Formatting
  • Linting
  • Release

Root URL Admin Site 301 Response

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.

image

How to recreate

Set the admin site path to the root URL of the site in the project urls.py

urlpatterns = [
    path('', admin.site.urls)
]

Steps to resolve

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/';

image

Idea: use the ModelAdmin's search_fields

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.

How to exclude certain models?

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.

Python 3.12

Shouldn't be any issues, just update tox/setup/etc.

Search only working on the admin index page

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?

Automatically search through ForeignKey fields?

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?

Object ID prefix

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.