Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!