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.
* 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>
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>
* status: closed => new
* resolution: needsinfo =>
--
Ticket URL: <https://code.djangoproject.com/ticket/24387#comment:3>
* 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>