Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

270
Vistas
Filtering objects in django admin

I want to manage objects in django admin, though I would like to be able only to edit objects with a specific value of some attribute. Precisely I have now in admin.py:

class UnitAdmin(admin.ModelAdmin):
    list_display = ('type', 'name', 'result_file')
    list_filter = ['type']
admin.site.register(Unit, UnitAdmin)

And I would like to manage only units with type='SomeSpecificType'. I saw something with overriding SimpleListFilter class, though I can't see how this applies here.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You have to override the get_queryset in de modelAdmin and filter objects that have type='SomeSpecificType.

class UnitAdmin(admin.ModelAdmin):
    ...

    def get_queryset(self, request):
        qs = super(UnitAdmin, self).get_queryset(request)
        return qs.filter(type='SomeSpecificType')
over 4 years ago · Santiago Trujillo Denunciar

0

You can do

class UnitAdmin(admin.ModelAdmin):
    list_display = ('type', 'name', 'result_file')
    list_filter = ['type']

    def get_readonly_fields(self, request, obj=None):
        if obj and obj.type == 'SomeSpecificType':
            return []
        return ["type", "name", "result_file"]
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda