Django Admin, custom queryset, can't groupe by (Exception Value: 'dict' object has no attribute '_meta')

43 views
Skip to first unread message

ebuild

unread,
Feb 22, 2015, 2:23:19 AM2/22/15
to django...@googlegroups.com
I have this model which map to a postgresql view

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')

What I want to achieve is to have region > sum(nbr), so:

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

But Django is throwing an exception:

Exception Value: 'dict' object has no attribute '_meta'
Exception Location: D:\Python335\lib\site-packages\django\contrib\admin\util.py in lookup_field, line 242
Note when I remove .values("region") the exception doesn't occure.

Am I missing something ?










Reply all
Reply to author
Forward
0 new messages