[Answer]-What about saving extra variable in a QuerySet?


You always can use the extra method, like this:

folder=Folder.objects.all().extra(select = {'fcount':33})

So, for each f in your folder queryset you will have some fcount property.

It works like an SQL Alias.

If you want to use with some other data based on your model you have to use annotate(https://docs.djangoproject.com/en/dev/ref/models/querysets/#annotate), maybe with a custom aggregation function(https://docs.djangoproject.com/en/dev/topics/db/aggregation/).

Leave a comment