Opened 8 years ago

Closed 5 years ago

#19258 closed Bug (duplicate)

ModelAdmin customized queryset with extra option

Reported by: honyczek Owned by: arank
Component: contrib.admin Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If you customize queryset in ModelAdmin:

from app.models import License, Server
from django.contrib import admin

class LicenseAdmin(admin.ModelAdmin):
  def queryset(self, request):
    qs = super(LicenseAdmin, self).queryset(request)
    return qs.extra(select={'usage_count': "SELECT COUNT(id) FROM app_server WHERE",})

  list_display = ('name','description','product_key', 'usage_count'), LicenseAdmin)

and want to use extra field called usage_count, you get an error:

ImproperlyConfigured at /admin/app/license/

LicenseAdmin.list_display[3], 'usage_count' is not a callable or an attribute of 'LicenseAdmin' or found in the model 'License'.

Django Admin interface ignores extra field usage_count from QuerySet, or validates columns by another way, which doesn't include QuerySet changes.

Change History (3)

comment:1 Changed 8 years ago by Julien Phalip

Triage Stage: UnreviewedAccepted

comment:2 Changed 7 years ago by arank

Owner: changed from nobody to arank
Status: newassigned

comment:3 Changed 5 years ago by Tim Graham

Resolution: duplicate
Status: assignedclosed

Duplicate of #14336

Note: See TracTickets for help on using tickets.
Back to Top