It's not really a matter of "working around" it. Your .xxx method/
property is an attribute of the object. What you evidently want from
the database is *not* a list of those objects, but rather a summary
representation of them. Trying to apply your .xxx is meaningless as
you don't have a discrete o
I think you didn't really look well anotate, because it looks like it
is what you qre looking for ! Or is there something I misunderstood ?
http://docs.djangoproject.com/en/dev/ref/models/querysets/#annotate-args-kwargs
"Annotates each object in the QuerySet with the provided list of
aggregate va
Yes, I'm aware of the background of the problem but i was wondering if
I can somehow "workaround" it.
Thanks for Your help
On 10 Cze, 23:34, Dan Harris wrote:
> The problem is the GROUP BY you are looking to get. The problem with
> doing a group by you don't get the whole object which is what th
Here is an example:
# In models.py
class TestModel(models.Model):
name = models.CharField()
# Get a listing of unique names and their counts
# In some view
from django.db.models import Count
TestModel.objects.values("name").annotate(Count("name"))
This will return a list of the form:
[{'na
The problem is the GROUP BY you are looking to get. The problem with
doing a group by you don't get the whole object which is what the
Django queryset is trying to return:
res = queryset.annotate(Count("name"))
This will give you a result set that you want and you can iterate over
like:
{% for r
Hi there!
I have a question. If i have a model with some fields (let's say all
CharFields named aaa,bbb,ccc etc. and some calculated properties named
xxx and zzz) how can I obtain something similar to
"SELECT aaa, count(aaa) FROM my_model_table GROUP BY aaa;"
i.e. a list of - lazy loaded - objects
Thanks.
I've already tried that but this isn't quite what i'm looking for. As
u wrote this returns a list, but I would like to obtain my calculated
property when I'm iterating over this. Like so (let's say the result
is in res variable) :
{% for r in res %}
{{r.xxx}} - {{r.name__count}}
{% end
7 matches
Mail list logo