Opened 13 years ago
Closed 10 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 , 13 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 13 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 10 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
Duplicate of #14336