Finder in Django administrator

0

In the django administrator, is there any way to enable a search engine?

You have a button to add a record, but when these records are too many, it is too late to find a record to modify or delete. In the image 14 thousand records are shown, it makes it take time to find (X) record.

    
asked by Noel L 27.01.2018 в 04:19
source

2 answers

0

I will assume that your model is a Part with the attributes parte , activo and descripcion . To enable the search engine and filters go to the file 'admin.py' that is in the folder of your application and write the following code:

class ParteAdmin(admin.ModelAdmin):
    # con esto muestras los campos que deses al mostrar la lista en admin
    list_display=['parte', 'activo']
    # con esto añades un campo de texto que te permite realizar la busqueda, puedes añadir mas de un atributo por el cual se filtrará
    search_fields = ['parte', 'descripcion']
    # con esto añadiras una lista desplegable con la que podras filtrar (activo es un atributo booleano)
    list_filter = ['activo']

at the end of the file admin.py you have to register your custom model

 admin.site.register(Parte, ParteAdmin)

the first parameter is the model and the second the class that we just made

    
answered by 27.01.2018 / 11:07
source
0

Use search_fields to enable the search box in the admin.

Example:

...
search_fields = ['nombre', 'apellido']
...

You can also search for a related object via ForeignKey or ManyToManyField using:

search_fields = ['user__email', ]

Official django documents

    
answered by 27.01.2018 в 06:43