[Django] #24387: Django admin, exception in queryset when using values() before annotate

47 views
Skip to first unread message

Django

unread,
Feb 22, 2015, 3:34:20 AM2/22/15
to django-...@googlegroups.com
#24387: Django admin, exception in queryset when using values() before annotate
-------------------------+-------------------------------------------------
Reporter: essadek | Owner: nobody
Type: Bug | Status: new
Component: | Version: 1.6
contrib.admin | Keywords: Django Admin , aggregation, change
Severity: Normal | list
Triage Stage: | Has patch: 0
Unreviewed |
Easy pickings: 0 | UI/UX: 0
-------------------------+-------------------------------------------------
{{{
class AppModel(models.Model):

nbr = models.BigIntegerField(blank=True, null=True)
region = models.ForeignKey(AppWilaya,blank=True, null=True)
date_preorder = models.DateField(blank=True, null=True)
id = models.IntegerField(primary_key=True,blank=True,
db_column='dummy_id')
}}}

{{{
class AppModelAdmin(admin.ModelAdmin):
....
def queryset(self, request):
qs = super(AppModelAdmin, self).get_queryset(request)
qs=qs.values("region").annotate(total=Sum( 'nbr'))
}}}


'''Exception Value: 'dict' object has no attribute '_meta'
Exception Location: [PATH_TO]\lib\site-
packages\django\contrib\admin\util.py in lookup_field, line 242'''

Note when removing '''.values("region")''' the exception doesn't occur.

--
Ticket URL: <https://code.djangoproject.com/ticket/24387>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 22, 2015, 11:30:45 AM2/22/15
to django-...@googlegroups.com
#24387: Django admin, exception in queryset when using values() before annotate
-------------------------------------+-------------------------------------
Reporter: essadek | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.6
Severity: Normal | Resolution: needsinfo
Keywords: Django Admin , | Triage Stage:
aggregation, change list | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* status: new => closed
* cc: charettes (added)
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* resolution: => needsinfo


Comment:

It's not clear to me what you're trying to accomplish here, the admin
requires a normal queryset not a value one.

Are you trying to select only the `region` field? In this case you should
use [https://docs.djangoproject.com/en/1.7/topics/db/optimization/#use-
queryset-defer-and-only only] and not `values`.

{{{#!python
qs = qs.annotate(total=Sum('nbr')).only('region')
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24387#comment:1>

Django

unread,
Feb 22, 2015, 1:37:47 PM2/22/15
to django-...@googlegroups.com
#24387: Django admin, exception in queryset when using values() before annotate
-------------------------------------+-------------------------------------
Reporter: essadek | Owner: nobody

Type: Bug | Status: closed
Component: contrib.admin | Version: 1.6
Severity: Normal | Resolution: needsinfo
Keywords: Django Admin , | Triage Stage:
aggregation, change list | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by essadek):

What is needed is aggregation, means '''sum(nbr )group by region''':

{{{
SELECT region, \
SUM(nbr) AS total\
FROM app_model\
GROUP BY region\
}}}

Never seen usage of '''"only()"''' In all search I've done on aggregation
in Django Admin.

--
Ticket URL: <https://code.djangoproject.com/ticket/24387#comment:2>

Django

unread,
Feb 22, 2015, 1:40:21 PM2/22/15
to django-...@googlegroups.com
#24387: Django admin, exception in queryset when using values() before annotate
-------------------------------------+-------------------------------------

Reporter: essadek | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.6
Severity: Normal | Resolution:
Keywords: Django Admin , | Triage Stage:
aggregation, change list | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by essadek):

* status: closed => new
* resolution: needsinfo =>


--
Ticket URL: <https://code.djangoproject.com/ticket/24387#comment:3>

Django

unread,
Feb 24, 2015, 9:08:16 AM2/24/15
to django-...@googlegroups.com
#24387: Django admin, exception in queryset when using values() before annotate
-------------------------------------+-------------------------------------
Reporter: essadek | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.6
Severity: Normal | Resolution: invalid

Keywords: Django Admin , | Triage Stage:
aggregation, change list | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* status: new => closed

* resolution: => invalid


Comment:

Please see TicketClosingReasons/UseSupportChannels for other ways to get
help with constructing proper queries besides reading the documentation.
The information you've provided so far suggests problems in your own code,
not in Django itself.

--
Ticket URL: <https://code.djangoproject.com/ticket/24387#comment:4>

Reply all
Reply to author
Forward
0 new messages