I have the following code in the admin.py #Aparated 1 implements a search engine in the admin #Apart 2 and 3 Implement export and import options
The search engine is correctly displayed in the admin of django, but when I add sections 2 and 3, the search engine disappears and is displayed as the attached image shows.
If I enable the search engine, the import export and vicerversa buttons disappear.
Neither the export button is displayed, unless you select the Action drop-down menu:
Try to create a new class for #Apart 1, that is, ShareAdministrator and register it like this: admin.site.register (PartAdministrator) however, I get the following error: TypeError: MediaDefiningClass object is not iterable.
The last image shows an example of how the export and import buttons should be displayed in the admin, obviously that image does not include the search engine.
from import_export import resources
from import_export.admin import ImportExportModelAdmin
from import_export.admin import ImportExportActionModelAdmin
#Modelo original el cual esta en models.py
from app.models import Parte
#Apartado 1
class ParteAdmin(admin.ModelAdmin):
# con esto muestras los campos que deses al mostrar la lista en admin
list_display=['id','numero','modelo','unidad', 'proyecto','precio','tipo']
# con esto se añade un campo de texto que permite realizar la busqueda, se puede añadir mas de un atributo por el cual se filtrará
search_fields = ['unidad', 'proyecto','numero', 'modelo','tipo']
# con esto se añade una lista desplegable con la que se podra filtrar ( es un atributo booleano)
list_filter = ['tipo','nivel','unidad','proyecto']
#Apartado 2
#Clase que define que modelo va tener implementado las opciones de importacion y exportacion
class ParteResource(resources.ModelResource):
class Meta:
model = Parte
#Apartado 3
class ParteAdmin(ImportExportModelAdmin):
resource_class = ParteResource
#Apartado 4
class ParteAdmin(ImportExportActionModelAdmin):
pass
admin.site.register(Parte,ParteAdmin)