Opened 11 years ago

Closed 9 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

Description

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 license_id=license.id",})

  list_display = ('name','description','product_key', 'usage_count')
  
admin.site.register(License, 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 by Julien Phalip, 11 years ago

Triage Stage: UnreviewedAccepted

comment:2 by arank, 11 years ago

Owner: changed from nobody to arank
Status: newassigned

comment:3 by Tim Graham, 9 years ago

Resolution: duplicate
Status: assignedclosed

Duplicate of #14336

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